Node.js (Advanced) Suresh Reddy Senior Software Engineer Echidna, Inc.
Agenda  What is Node.JS  Using Node.JS  Common Modules  Streams  Express  Load balancing  Competitors  References
What is Node.JS  JavaScript programming environment for creating highly scalable network programs  Provides evented, Non-blocking I/O  Built on top of V8 Node.JS is bare bone and the community are making stuff like Express, connect etc.
What is Node.JS Event driven programming $.ajax( url:'http://example.com/getProducts?cid=132867', type:'GET', contentType:'application/json', success:function(response){// doWithResponse }, error:function(xhr){// Error :( } );
Using Node.JS  Install Node.JS  wget http://nodejs.org/dist/node-v0.1.96.tar.gz  gunzip node-v0.1.96.tar.gz  cd node  ./configure  make  make install  NPM  Install/Publish other modules you want by doing  npm install <module_name>  npm publish <module_name>
Node.JS – as an interactive shell Similar to Python’s shell $> node >3+1 4 > true != false true >.help >.exit
Node.JS – As a server var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello Worldn'); }).listen(1337, "127.0.0.1"); console.log('Server running at 127.0.0.1:1337');
Core Modules  Processes  Filesystem  Networking  Utilities The entire list can be found at http://nodejs.org/api/
Core Modules - Processes Node allows you to analyze your process and manage external process Available Modules  process  child_process
Core Modules - Filesystem Low level API to manipulate files Available Modules  fs  path
Core Modules - Networking Available Modules  net  dgram  http  tls  https  dns
Express  Basic web framework  Runs on top of Node.js  Provides routing and redirection helpers  Dynamic view helpers  Has support for session  Focus on high performance
Hello World Express App
Streams  Stream instances are Unix pipes  Readable  must emit ”data” events whenever they have data to be read and ”end” when the data stream is finished.  Writable  must implement the write() method to accept new data chunks into the stream and the end() method to instruct the stream that the data is finished.
Node.JS is useful for..  Writing highly concurrent server applications  Sharing application logic between server and client  Peer-to-peer web applications using websockets  Real-time applications
Load Balancing The ability to distribute work load across multiple servers  HAProxy  Nginix  Apache Http server
Other Asynchronous JavaScript platforms  Tornado and Twisted for Python  Perl Object Environment for Perl  libevent for C  Vert.x for Java  EventMachine for Ruby  vibe.d for D
Links  http://nodejs.org  http://npmjs.org  http://expressjs.com  http://socket.io
Thank you

Node js beginner

  • 1.
    Node.js (Advanced) Suresh Reddy Senior Software Engineer Echidna, Inc.
  • 2.
    Agenda  What is Node.JS  Using Node.JS  Common Modules  Streams  Express  Load balancing  Competitors  References
  • 3.
    What is Node.JS  JavaScript programming environment for creating highly scalable network programs  Provides evented, Non-blocking I/O  Built on top of V8 Node.JS is bare bone and the community are making stuff like Express, connect etc.
  • 4.
    What is Node.JS Eventdriven programming $.ajax( url:'http://example.com/getProducts?cid=132867', type:'GET', contentType:'application/json', success:function(response){// doWithResponse }, error:function(xhr){// Error :( } );
  • 5.
    Using Node.JS  Install Node.JS  wget http://nodejs.org/dist/node-v0.1.96.tar.gz  gunzip node-v0.1.96.tar.gz  cd node  ./configure  make  make install  NPM  Install/Publish other modules you want by doing  npm install <module_name>  npm publish <module_name>
  • 6.
    Node.JS – asan interactive shell Similar to Python’s shell $> node >3+1 4 > true != false true >.help >.exit
  • 7.
    Node.JS – Asa server var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello Worldn'); }).listen(1337, "127.0.0.1"); console.log('Server running at 127.0.0.1:1337');
  • 8.
    Core Modules  Processes  Filesystem  Networking  Utilities The entire list can be found at http://nodejs.org/api/
  • 9.
    Core Modules -Processes Node allows you to analyze your process and manage external process Available Modules  process  child_process
  • 10.
    Core Modules -Filesystem Low level API to manipulate files Available Modules  fs  path
  • 11.
    Core Modules -Networking Available Modules  net  dgram  http  tls  https  dns
  • 12.
    Express  Basic web framework  Runs on top of Node.js  Provides routing and redirection helpers  Dynamic view helpers  Has support for session  Focus on high performance
  • 13.
  • 14.
    Streams  Stream instances are Unix pipes  Readable  must emit ”data” events whenever they have data to be read and ”end” when the data stream is finished.  Writable  must implement the write() method to accept new data chunks into the stream and the end() method to instruct the stream that the data is finished.
  • 15.
    Node.JS is usefulfor..  Writing highly concurrent server applications  Sharing application logic between server and client  Peer-to-peer web applications using websockets  Real-time applications
  • 16.
    Load Balancing The abilityto distribute work load across multiple servers  HAProxy  Nginix  Apache Http server
  • 17.
    Other Asynchronous JavaScript platforms  Tornado and Twisted for Python  Perl Object Environment for Perl  libevent for C  Vert.x for Java  EventMachine for Ruby  vibe.d for D
  • 18.
    Links  http://nodejs.org  http://npmjs.org  http://expressjs.com  http://socket.io
  • 19.