SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Node Architecture and Getting Started with Express
Node Architecture and Getting Started with ExpressNode Architecture and Getting Started with Express
Node Architecture and Getting Started with Express
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Vue js for beginner
Vue js for beginner Vue js for beginner
Vue js for beginner
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Node js
Node jsNode js
Node js
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
React js
React jsReact js
React js
 
React workshop
React workshopReact workshop
React workshop
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Express JS
Express JSExpress JS
Express JS
 
Bootstrap 4 ppt
Bootstrap 4 pptBootstrap 4 ppt
Bootstrap 4 ppt
 
JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)JavaScript Object Notation (JSON)
JavaScript Object Notation (JSON)
 
NodeJS - Server Side JS
NodeJS - Server Side JS NodeJS - Server Side JS
NodeJS - Server Side JS
 
RESTful API In Node Js using Express
RESTful API In Node Js using Express RESTful API In Node Js using Express
RESTful API In Node Js using Express
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 

Destaque

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
 

Destaque (6)

Design patterns
Design patternsDesign patterns
Design patterns
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
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
 

Semelhante a 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
 

Semelhante a 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
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
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
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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...
 
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...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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