SlideShare a Scribd company logo
1 of 21
Getting started with
What is NodeJS ?
NodeJS is a platform built on Google’s V8
javascript engine for easily building scalable
network applications.
Advantages
  Event driven
  Nonblocking I/O Model
  Perfect for data intensive real time applications
  Lightweight and efficient
More about NodeJS
Is it all about developing server side code with
Javascript ?
Javascript provides an interface to V8.
What is this buzz about Google’s V8 javascript engine ?
  Powers Google Chrome.
  Translates javascript to assembly code
  Crankshaft JIT compiler
How is NodeJS different from other scripting
paradigms like Perl/PHP/Python/Ruby on Rails?
  Non Blocking
  Single threaded
  In built event based approach
Traditional I/O
Traditional I/O
Event based Non-Blocking I/O
How Non-Blocking I/O helps ?
                                       E
var mysql = require('db-mysql');       r
new mysql.Database(                    o
{                                      r
hostname: 'localhost‘,user: 'root‘,
password: '‘, database: 'kino_badge’}).on('error', function(error) {
     console.log('ERROR: ' + error);
}).on('ready', function(server) {            On Ready
    console.log('Connected to ' + server.hostname + ' (' + server.version + ')');
}).connect(function(error){
     if(error){
                                     connected
       console.log("connection error " + error);
     }
 this.query().select('*').from('appUser').execute(function(error,rows,columns){
       if(error){
         console.log("Error: " + error);                       R
         return;
       }                                                       e
       console.log("Rows : " + JSON.stringify(rows));          s
     });                                                       u
});
                                                              l
                                                              t
Why Javascript is the chosen one ?
 Inherently single threaded.
 Functions and Closures are available as first
 class objects
 No preconceived notions about I/O
 Event orientation at its core
 Present everywhere
   Browsers
   Webkits
NodeJS community and NPM
What is NPM
  Node packaged module.
  Third party Libraries, can be used with nodejs
What all modules are available for application
development
  16762 open source libraries available, and counting.
To install dependencies using NPM
  Any package can be installed using npm install
  Full instruction set can be referred at
  https://npmjs.org/doc/install.html
NodeJS in real world !!
• Linked-In Mobile app.
• Four Square Application
Want to program in                     ?
Be event oriented
Think in terms of callbacks on event
completion and error occurrences
Design using closures and callbacks
Let’s code with
A hello world program

A http server

List files on server
How callback works ?


console.log(‘Hello’);
setTimeout(function(){      callback
 console.log(‘World’);
},2000);
Callbacks revisited..

 var http = require("http");             HTTP Module

Create Server
 http.createServer(
     function(request,response){      Callback on request
         response.writeHead(200,{'Content-Type'
   : 'text/plain'});
         response.end("Hi I am running on
   NodeJSn");
     }
 ).listen(8124,'127.0.0.1');      Listen to Port

 console.log("server running at
   http://localhost:8124");
Detailed Example
var fs = require('fs');
var express = require('express');
var app = express(); app.listen(3000);

fs.readdir('../',function(err,files){
         console.log(files.length);
});
app.get('/file/index/:user', function(request, response) {
var user_directory = request.params.user;
fs.readdir(user_directory,function(err,files){
         if(err){
                      console.log(err);
                      response.send(JSON.stringify(err));
         }else{
response.set('Content-Type', 'text/html');
var dyna_html =
  '<html><head></head><body><table style="width:100px; height;200px;border: 1px solid black;">';
for(var i=0;i<files.length;i++){
         var dyna_col = '<tr><td>'+files[i]+'</td></tr>'
         dyna_html += dyna_col;
}
 dyna_html +='</table></body></html>';
 response.send(200, dyna_html); }});});
Let’s break with NodeJS
How to break with NodeJS
  Programming modularly
  Developing larger applications
Developing for the Web



                        ExpressJS


            MVC                     REST
Simple Examples
exports.world = function(){
  return 'hello world';
                                    hello.js
};




  var hello = require('./hello');
  var sys = require('util');
  sys.puts(hello.world());
                                    app.js
Complete JavaScript EcoSystem
Developing REST based Web app with
ExpressJS
Adding persistence layer with MongoDB
Managing security with OAuth using
  Google - PassportJS
  Facebook - facebook-node-sdk
Communicating with the Client side javascript
implemented in SmartClientJS
Questions…
Alok Guha                             Hussain Pithawala

      aalokism                             hussainpw

http://in.linkedin.com/in/alokguha   http://in.linkedin.com/in/hussainpithawala

More Related Content

What's hot

Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/jsKnoldus Inc.
 
Java servlets
Java servletsJava servlets
Java servletslopjuan
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBhargav Anadkat
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 

What's hot (20)

Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Java servlets
Java servletsJava servlets
Java servlets
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
jQuery
jQueryjQuery
jQuery
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Javascript
JavascriptJavascript
Javascript
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Java script
Java scriptJava script
Java script
 
Master page in Asp.net
Master page in Asp.netMaster page in Asp.net
Master page in Asp.net
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Javascript
JavascriptJavascript
Javascript
 

Viewers also liked

Design patterns
Design patternsDesign patterns
Design patternsAlok Guha
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script PromiseAlok Guha
 
Portfolio Undefined
Portfolio UndefinedPortfolio Undefined
Portfolio Undefined<Undefined>
 
Aglie estimation and planning
Aglie estimation and planningAglie estimation and planning
Aglie estimation and planningAlok Guha
 

Viewers also liked (7)

Design patterns
Design patternsDesign patterns
Design patterns
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
Express JS
Express JSExpress JS
Express JS
 
Jasmine
JasmineJasmine
Jasmine
 
Portfolio Undefined
Portfolio UndefinedPortfolio Undefined
Portfolio Undefined
 
Q unit
Q unitQ unit
Q unit
 
Aglie estimation and planning
Aglie estimation and planningAglie estimation and planning
Aglie estimation and planning
 

Similar to NodeJS

Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Node js introduction
Node js introductionNode js introduction
Node js introductionAlex Su
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comVan-Duyet Le
 
Node js
Node jsNode js
Node jshazzaz
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETGianluca Carucci
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...GITS Indonesia
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.xYiguang Hu
 

Similar to NodeJS (20)

Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Introduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.comIntroduce about Nodejs - duyetdev.com
Introduce about Nodejs - duyetdev.com
 
Node js
Node jsNode js
Node js
 
Event driven programming -- Node.JS
Event driven programming -- Node.JSEvent driven programming -- Node.JS
Event driven programming -- Node.JS
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
Node intro
Node introNode intro
Node intro
 
node.js dao
node.js daonode.js dao
node.js dao
 
Introduction to Vert.x
Introduction to Vert.xIntroduction to Vert.x
Introduction to Vert.x
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

NodeJS

  • 2. What is NodeJS ? NodeJS is a platform built on Google’s V8 javascript engine for easily building scalable network applications. Advantages Event driven Nonblocking I/O Model Perfect for data intensive real time applications Lightweight and efficient
  • 3. More about NodeJS Is it all about developing server side code with Javascript ? Javascript provides an interface to V8. What is this buzz about Google’s V8 javascript engine ? Powers Google Chrome. Translates javascript to assembly code Crankshaft JIT compiler How is NodeJS different from other scripting paradigms like Perl/PHP/Python/Ruby on Rails? Non Blocking Single threaded In built event based approach
  • 7. How Non-Blocking I/O helps ? E var mysql = require('db-mysql'); r new mysql.Database( o { r hostname: 'localhost‘,user: 'root‘, password: '‘, database: 'kino_badge’}).on('error', function(error) { console.log('ERROR: ' + error); }).on('ready', function(server) { On Ready console.log('Connected to ' + server.hostname + ' (' + server.version + ')'); }).connect(function(error){ if(error){ connected console.log("connection error " + error); } this.query().select('*').from('appUser').execute(function(error,rows,columns){ if(error){ console.log("Error: " + error); R return; } e console.log("Rows : " + JSON.stringify(rows)); s }); u }); l t
  • 8. Why Javascript is the chosen one ? Inherently single threaded. Functions and Closures are available as first class objects No preconceived notions about I/O Event orientation at its core Present everywhere Browsers Webkits
  • 9. NodeJS community and NPM What is NPM Node packaged module. Third party Libraries, can be used with nodejs What all modules are available for application development 16762 open source libraries available, and counting. To install dependencies using NPM Any package can be installed using npm install Full instruction set can be referred at https://npmjs.org/doc/install.html
  • 10.
  • 11. NodeJS in real world !! • Linked-In Mobile app. • Four Square Application
  • 12. Want to program in ? Be event oriented Think in terms of callbacks on event completion and error occurrences Design using closures and callbacks
  • 13. Let’s code with A hello world program A http server List files on server
  • 14. How callback works ? console.log(‘Hello’); setTimeout(function(){ callback console.log(‘World’); },2000);
  • 15. Callbacks revisited.. var http = require("http"); HTTP Module Create Server http.createServer( function(request,response){ Callback on request response.writeHead(200,{'Content-Type' : 'text/plain'}); response.end("Hi I am running on NodeJSn"); } ).listen(8124,'127.0.0.1'); Listen to Port console.log("server running at http://localhost:8124");
  • 16. Detailed Example var fs = require('fs'); var express = require('express'); var app = express(); app.listen(3000); fs.readdir('../',function(err,files){ console.log(files.length); }); app.get('/file/index/:user', function(request, response) { var user_directory = request.params.user; fs.readdir(user_directory,function(err,files){ if(err){ console.log(err); response.send(JSON.stringify(err)); }else{ response.set('Content-Type', 'text/html'); var dyna_html = '<html><head></head><body><table style="width:100px; height;200px;border: 1px solid black;">'; for(var i=0;i<files.length;i++){ var dyna_col = '<tr><td>'+files[i]+'</td></tr>' dyna_html += dyna_col; } dyna_html +='</table></body></html>'; response.send(200, dyna_html); }});});
  • 17. Let’s break with NodeJS How to break with NodeJS Programming modularly Developing larger applications Developing for the Web ExpressJS MVC REST
  • 18. Simple Examples exports.world = function(){ return 'hello world'; hello.js }; var hello = require('./hello'); var sys = require('util'); sys.puts(hello.world()); app.js
  • 19. Complete JavaScript EcoSystem Developing REST based Web app with ExpressJS Adding persistence layer with MongoDB Managing security with OAuth using Google - PassportJS Facebook - facebook-node-sdk Communicating with the Client side javascript implemented in SmartClientJS
  • 21. Alok Guha Hussain Pithawala aalokism hussainpw http://in.linkedin.com/in/alokguha http://in.linkedin.com/in/hussainpithawala