Published on

It is presentation slides of nodeJS session, presented by Hussain and me in techNext.

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Getting started with
  2. 2. What is NodeJS ?NodeJS is a platform built on Google’s V8javascript engine for easily building scalablenetwork applications.Advantages Event driven Nonblocking I/O Model Perfect for data intensive real time applications Lightweight and efficient
  3. 3. More about NodeJSIs it all about developing server side code withJavascript ?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 compilerHow is NodeJS different from other scriptingparadigms like Perl/PHP/Python/Ruby on Rails? Non Blocking Single threaded In built event based approach
  4. 4. Traditional I/O
  5. 5. Traditional I/O
  6. 6. Event based Non-Blocking I/O
  7. 7. How Non-Blocking I/O helps ? Evar mysql = require(db-mysql); rnew mysql.Database( o{ rhostname: 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. 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. 9. NodeJS community and NPMWhat is NPM Node packaged module. Third party Libraries, can be used with nodejsWhat all modules are available for applicationdevelopment 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
  10. 10. NodeJS in real world !!• Linked-In Mobile app.• Four Square Application
  11. 11. Want to program in ?Be event orientedThink in terms of callbacks on eventcompletion and error occurrencesDesign using closures and callbacks
  12. 12. Let’s code withA hello world programA http serverList files on server
  13. 13. How callback works ?console.log(‘Hello’);setTimeout(function(){ callback console.log(‘World’);},2000);
  14. 14. Callbacks revisited.. var http = require("http"); HTTP ModuleCreate 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,; Listen to Port console.log("server running at http://localhost:8124");
  15. 15. Detailed Examplevar 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); }});});
  16. 16. Let’s break with NodeJSHow to break with NodeJS Programming modularly Developing larger applicationsDeveloping for the Web ExpressJS MVC REST
  17. 17. Simple = function(){ return hello world; hello.js}; var hello = require(./hello); var sys = require(util); sys.puts(; app.js
  18. 18. Complete JavaScript EcoSystemDeveloping REST based Web app withExpressJSAdding persistence layer with MongoDBManaging security with OAuth using Google - PassportJS Facebook - facebook-node-sdkCommunicating with the Client side javascriptimplemented in SmartClientJS
  19. 19. Questions…
  20. 20. Alok Guha Hussain Pithawala aalokism hussainpw