0
Introduction to
Node.js
How does it work? What makes it different? When would you use

it? And most importantly, why does ...
What is Node.js?
Development platform

Event-

Non-blocking I/O

driven

model

Built on Chrome's JavaScript

engine

“Nod...
Wait a minute….

Umm…not
really.
JavaScript on the server

JavaScript was supposed to
be a server-side language as
well.
Netscape Enterprise Server

“ Netscape Enterprise Server 2.0 is the first web server to
support the Java(TM) and JavaScrip...
Traditional web servers

Anyway, let’s see how web servers work
currently…
Current setup
Request 1

Thread 1

…

Request 2

Thread 2

…

Request n

Typically
….
Each request to a traditional web
se...
How does it scale?

So if there are 10,000 requests
coming in at the same time, and
each requires executing a longrunning ...
How does node.js address it?

So what does node.js bring to the table?

Single thread processing.
And how does it work?
behind the
scenes

Source: http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Deve...
Simple “hello world” app
hello-world app in
node.js
// Load the http module to create an http server.
var http = require('...
Demo

Let’s write some code.
What makes it different?
It’s JavaScript! (everybody know JavaScript,
right?)
Single threaded (avoid concurrency issues)
(...
Why does it matter?
It matters because just like with any other
technology, Node.js is not perfect.
Don’t start using it b...
When should you use it?
Multi user, real time apps
- mobile games, collaboration tools, chat rooms, etc.

APIs exposing JS...
We’re done

Questions
?

Girish
Gangadharan

@appoosa
Upcoming SlideShare
Loading in...5
×

Introduction to node

388

Published on

How does it work? What makes it different? When would you use it? And most importantly, why does it matter?

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
388
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Introduction to node"

  1. 1. Introduction to Node.js How does it work? What makes it different? When would you use it? And most importantly, why does it matter? Girish Gangadharan @appoosa
  2. 2. What is Node.js? Development platform Event- Non-blocking I/O driven model Built on Chrome's JavaScript engine “Node.js is lightweight and efficient which makes it perfect for building fast, scalable network applications that run across distributed devices.”
  3. 3. Wait a minute…. Umm…not really.
  4. 4. JavaScript on the server JavaScript was supposed to be a server-side language as well.
  5. 5. Netscape Enterprise Server “ Netscape Enterprise Server 2.0 is the first web server to support the Java(TM) and JavaScript(TM) programming languages, enabling the creation, delivery and management of live online applications. ”(March 1996) Source: http://www.thefreelibrary.com/NETSCAPE+INTRODUCES+NETSCAPE+ENTERPRISE+SERVER(TM)+2.0-a018056425
  6. 6. Traditional web servers Anyway, let’s see how web servers work currently…
  7. 7. Current setup Request 1 Thread 1 … Request 2 Thread 2 … Request n Typically …. Each request to a traditional web server gets handed over to a thread (picked from a limited thread pool) for processing. Thread m (m < n) (for a busy site, m could be a fraction of n)
  8. 8. How does it scale? So if there are 10,000 requests coming in at the same time, and each requires executing a longrunning task (DB transactions, network I/O, etc.) ….
  9. 9. How does node.js address it? So what does node.js bring to the table? Single thread processing.
  10. 10. And how does it work? behind the scenes Source: http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx
  11. 11. Simple “hello world” app hello-world app in node.js // Load the http module to create an http server. var http = require('http'); // Configure the HTTP server. var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Hello, world"); }); // Listen on port 8000, IP defaults to 127.0.0.1 server.listen(3000); // Log message to the terminal console.log("Server running at http://127.0.0.1:3000/");
  12. 12. Demo Let’s write some code.
  13. 13. What makes it different? It’s JavaScript! (everybody know JavaScript, right?) Single threaded (avoid concurrency issues) (single threaded out of the box, but still supports multi-threading) Super efficient (can handle 100s of 1000s of connections/minute) Great for real-time applications (because of low latency) Vibrant community (15,000+ packages) And….it’s FREE! (no licensing costs, no expensive dev tools)
  14. 14. Why does it matter? It matters because just like with any other technology, Node.js is not perfect. Don’t start using it because it’s new and shiny. for example, it’s not the best solution for CPU intensive requests processing We don’t need another bubble.
  15. 15. When should you use it? Multi user, real time apps - mobile games, collaboration tools, chat rooms, etc. APIs exposing JSON based DBs - no need to do any JSON conversion (since it’s JavaScript) Data Streaming - Can process files as they’re still being uploaded (using Streams) Single page apps - AJAX heavy apps can benefit from node’s low response times
  16. 16. We’re done Questions ? Girish Gangadharan @appoosa
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×