Node.JS Deep Dive       Training Deck By       Prasoon Kumar       Senior Technical Architect       Just Dial          Pre...
What is node?•   Server-side JavaScript framework•   Written using Google V8 engine•   Uses CommonJS module system•   Has ...
Who is using it?•   Sponsored by•   Google•   Microsoft (native support in Azure)•   Yahoo•   eBay•   Facebook•   LinkedIn...
Threads VS Event-driven            Threads                Asynchronous Event-drivenLock application / request with   only ...
Node is…
Node layers             Node standard libraryJavaScript             Node bindingsC             V8                      Thr...
What? Event looping…
Non-blocking IO• The philosophy behind node is that system interactions should be non  blocking.                      Inst...
Installation./configure --prefix=/opt/nodemakesudo make install[prasoonk@prasoonk node-v0.8.6]$ node –versionv0.8.6[prasoo...
What are packages?• Ruby has Gems• Python has PyPI• PHP has PEAR (terrible)           Node.js has Packages
Node Package Manager (NPM)• http://npmjs.org/
npm commands• ls [filter] – installed, stable, @1.0• Install package_name@version branch• rm
NPM – Node Package     Manager
API Tour• Platform   – process   – file system   – Networking      • net, dgram, http, tls (ssl)• Utility   – console   – ...
Process• Process – PID, platform, memory usage• Child_process –  – spawn and kill processes,  – Execute commands and  – Pi...
API Tour: File System• fs• path
Hello Worldserver.js File:var http = require(http);http.createServer(function (req, res) {    res.writeHead(200, {Content-...
Realtime apps          Real easyDERBY
All app code client and serverReal-time synced• Responsive• Offline• No glue code• SEO friendly
• C:srchello> npm install derby                DEMO
Visit Me @http://twitter.com/prasoonkhttp://prasoonk.wordpress.comhttp://slideshare.net/prasoonk           Thanks!
Quick References• https://github.com/joyent/node/wiki Github  Node Wiki• http://nodemanual.org - API docs, tutorials and  ...
Upcoming SlideShare
Loading in …5
×

Node.js introduction

2,017 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,017
On SlideShare
0
From Embeds
0
Number of Embeds
103
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Node.js introduction

  1. 1. Node.JS Deep Dive Training Deck By Prasoon Kumar Senior Technical Architect Just Dial Presentation Material1 18th August,2012
  2. 2. What is node?• Server-side JavaScript framework• Written using Google V8 engine• Uses CommonJS module system• Has the ECMASCript5 features• Non-blocking from ground up• Servers are normally thread based but Node.JS is “Event” based. Node. JS serves each request in an Evented loop that can able to handle simultaneous requests.
  3. 3. Who is using it?• Sponsored by• Google• Microsoft (native support in Azure)• Yahoo• eBay• Facebook• LinkedIn• Many, many smaller companies
  4. 4. Threads VS Event-driven Threads Asynchronous Event-drivenLock application / request with only one thread, whichlistener-workers threads repeatedly fetches an eventUsing incoming-request model Using queue and then processes itmultithreaded server might block manually saves state and thenthe request which might involve goes on to process the nextmultiple events eventUsing context switching no contention and no context switchesUsing multithreading Using asynchronous I/O facilitiesenvironments where listener and (callbacks, not poll/select orworkers threads are used O_NONBLOCK) environmentsfrequently to take an incoming-request lock
  5. 5. Node is…
  6. 6. Node layers Node standard libraryJavaScript Node bindingsC V8 Thread Event pool Pool libev libeio
  7. 7. What? Event looping…
  8. 8. Non-blocking IO• The philosophy behind node is that system interactions should be non blocking. Instead of this var fs = require(fs); // Import the fs module var data = fs.readFileSync(__dirname + /example.file,utf8); console.log(data); // print it! Use this var fs = require(fs); // Import the fs module // Read the file asynchronously fs.readFile(__dirname + /example.file, utf8, function (err, data) { if (err) { return console.log(err); } console.log(data); // print it! });
  9. 9. Installation./configure --prefix=/opt/nodemakesudo make install[prasoonk@prasoonk node-v0.8.6]$ node –versionv0.8.6[prasoonk@prasoonk node-v0.8.6]$ node 2+3 5 process.versions { http_parser: 1.0, node: 0.8.6, v8: 3.11.10.17, ares: 1.7.5-DEV, uv: 0.8, zlib: 1.2.3, openssl: 1.0.0f }
  10. 10. What are packages?• Ruby has Gems• Python has PyPI• PHP has PEAR (terrible) Node.js has Packages
  11. 11. Node Package Manager (NPM)• http://npmjs.org/
  12. 12. npm commands• ls [filter] – installed, stable, @1.0• Install package_name@version branch• rm
  13. 13. NPM – Node Package Manager
  14. 14. API Tour• Platform – process – file system – Networking • net, dgram, http, tls (ssl)• Utility – console – util• Buffer• Event Emitter• Timer
  15. 15. Process• Process – PID, platform, memory usage• Child_process – – spawn and kill processes, – Execute commands and – Pipe their outputs
  16. 16. API Tour: File System• fs• path
  17. 17. Hello Worldserver.js File:var http = require(http);http.createServer(function (req, res) { res.writeHead(200, {Content- Type:text/plain}); res.end(Hello, world! );}).listen(80);
  18. 18. Realtime apps Real easyDERBY
  19. 19. All app code client and serverReal-time synced• Responsive• Offline• No glue code• SEO friendly
  20. 20. • C:srchello> npm install derby DEMO
  21. 21. Visit Me @http://twitter.com/prasoonkhttp://prasoonk.wordpress.comhttp://slideshare.net/prasoonk Thanks!
  22. 22. Quick References• https://github.com/joyent/node/wiki Github Node Wiki• http://nodemanual.org - API docs, tutorials and live code samples• http://c9.io Cloud9 IDE (use github id)• http://docs.nodejitsu.com• http://howtonode.org/ Tutorials• https://npmjs.org/ NPM registry• https://github.com/WindowsAzure/azure-sdk- for-node

×