SlideShare a Scribd company logo
A language for the
                Internet
           Why JavaScript and Node.js is right for
                   Internet Applications




Tom Hughes-Croucher
@sh1mmer
Me
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
Scalable Server-Side Code with JavaScript




Node                     Up and Running




                        Tom Hughes-Croucher
Internet?
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
She’s called Eleanor
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
More features
 More users
More devices
 More data
Cost




       Stuff
How do we cope with
the increase in demand?
Internet Applications
How about search?
Browser



                     Server




   Spidering...   The Web
Would take forever!
Browser




          Front-end
            Server



          Database
Client → Server




                  Computation
Client → Server   Server → DB




         Computation     Computation
“Traditional” Approach
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
Server
Request
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
U L L
F
Event-driven Approach
Place-
holder
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
Shared
  Work
Resources
Welcome to Node.js
Node.js?

• Server Side JavaScript runtime
• Built on top of V8 JavaScript engine from
  Google Chrome
• Non-blocking I/O APIs
• Easy to extend APIs and modules
$Enki:~ $ node
$Enki:~ $ node
>3>2>1
false
> true == 1
true
> true === 1
false
> console.log('Hello World');
Hello World
> .help
.clear Break, and also clear the local context.
.exit Exit the prompt
.help Show repl options
> .clear
Clearing context...
> .exit
Enki:~ $
Enki:~ $ node
> var foo = "bar";
> foo;
'bar'
> .clear
Clearing context...
> foo
ReferenceError: foo is not defined
   at [object Context]:1:1
   at Interface.<anonymous> (repl:98:19)
   at Interface.emit (events:27:15)
   at Interface._ttyWrite (readline:295:12)
   at Interface.write (readline:132:30)
   at Stream.<anonymous> (repl:79:9)
   at Stream.emit (events:27:15)
   at IOWatcher.callback (net:489:16)
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
var http = require('http');

//include the http library
http.createServer(function (req, res) {

}).listen(8124, "127.0.0.1");

//create an http server
//when ‘stuff’ happens call this anonymous function
//listen on port 8124 of the IP 127.0.0.1
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
})

//when ‘stuff’ happens my function fires
//I get a request object and a response object
//I write to the response object header
//HTTP status 200 and content-type ‘text/plain’
//close the response with the body:
//Hello World
console.log('Server running at http://127.0.0.1:8124/');

//write Server is running at http://127.0.0.1:8124/
//to the console
Why is Node.js suited
 to Internet Apps?
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
What is the event
      loop?
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
Multi-tasking,
one thing at a time.
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
var http = require('http');
server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
});

server.listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
var http = require('http');
server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
});

server.listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');




              Step 1.
          Evaluate 'Main'
var http = require('http');
server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
});

server.listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');


                     Step 1.
   variables: http -> http module
          server -> http server

   listeners: server.request -> function
var http = require('http');
    server = http.createServer();


*
    server.on('request', function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello Worldn');
    });

    server.listen(8124, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:8124/');




                     Step 2.
                   Event Loop
var http = require('http');
    server = http.createServer();


*
    server.on('request', function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello Worldn');
    });

    server.listen(8124, "127.0.0.1");
    console.log('Server running at http://127.0.0.1:8124/');


                         Step 2.
               Do we have active listeners?

         listeners: server.request -> function

                   Yes! Wait for listeners.
var http = require('http');
server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
});

server.listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');




                 Step 3.
               Event Calls
var http = require('http');
server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
});

server.listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');


                     Step 3.
              'request' is called. Since

     listeners: server.request -> function

                      Call function
var http = require('http');
server = http.createServer();

server.on('request', function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Worldn');
});

server.listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');


                     Step 3.
                          Loop!
                     (go to Step 2.)
Breaking the event
       loop
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
EE = require('events').EventEmitter;
ee = new EE();

die = false;

ee.on('die', function() {
    die = true;
});

setTimeout(function() {
   ee.emit('die');
}, 100);

while(!die) {
}

console.log('done');
Why non-blocking
    matters
var result =
db.query("select * from T");
// use result
What are we
waiting for?
A language for the Internet: Why JavaScript and Node.js is right for Internet Application
"Blocking" is as bad
    as stopping
Event Loop vs.
   Threads
PHP


8mb


    8gb ram
 8000/8 = 1000
~1000 users per
    machine
Node.js
                                TCP = 2kb
                                HTTP = 6kb




      8gb ram
 8000/0.006 = 1.3m
1.3m/2 ~ 650k users
Apache vs NGINX
concurrency × reqs/sec




http://blog.webfaction.com/a-little-holiday-present
Apache vs NGINX
concurrency × memory




http://blog.webfaction.com/a-little-holiday-present
Node.js is designed for
communication, just like
   your applications
Thanks!
             Questions?

Tom Hughes-Croucher
@sh1mmer

More Related Content

PDF
Node.js - A Quick Tour
Felix Geisendörfer
 
KEY
Writing robust Node.js applications
Tom Croucher
 
PPTX
Java script at backend nodejs
Amit Thakkar
 
PDF
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
PPT
RESTful API In Node Js using Express
Jeetendra singh
 
KEY
node.js: Javascript's in your backend
David Padbury
 
PDF
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
KEY
OSCON 2011 - Node.js Tutorial
Tom Croucher
 
Node.js - A Quick Tour
Felix Geisendörfer
 
Writing robust Node.js applications
Tom Croucher
 
Java script at backend nodejs
Amit Thakkar
 
Non-blocking I/O, Event loops and node.js
Marcus Frödin
 
RESTful API In Node Js using Express
Jeetendra singh
 
node.js: Javascript's in your backend
David Padbury
 
Node.js and How JavaScript is Changing Server Programming
Tom Croucher
 
OSCON 2011 - Node.js Tutorial
Tom Croucher
 

What's hot (20)

PPTX
introduction to node.js
orkaplan
 
PDF
Server Side Event Driven Programming
Kamal Hussain
 
PDF
Nodejs Explained with Examples
Gabriele Lana
 
KEY
A million connections and beyond - Node.js at scale
Tom Croucher
 
PDF
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
Tom Croucher
 
KEY
Building a real life application in node js
fakedarren
 
PDF
Building servers with Node.js
ConFoo
 
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
PDF
Node.js in production
Felix Geisendörfer
 
PPT
Node js presentation
martincabrera
 
PPTX
Introduction to node.js GDD
Sudar Muthu
 
KEY
Introduction to node.js
jacekbecela
 
PPT
Building your first Node app with Connect & Express
Christian Joudrey
 
PDF
Introduction to Node.js: What, why and how?
Christian Joudrey
 
PDF
Node ppt
Tamil Selvan R S
 
KEY
Node.js - A practical introduction (v2)
Felix Geisendörfer
 
PDF
All aboard the NodeJS Express
David Boyer
 
PPTX
Intro to Node.js (v1)
Chris Cowan
 
KEY
Node.js - Best practices
Felix Geisendörfer
 
PDF
Complete MVC on NodeJS
Hüseyin BABAL
 
introduction to node.js
orkaplan
 
Server Side Event Driven Programming
Kamal Hussain
 
Nodejs Explained with Examples
Gabriele Lana
 
A million connections and beyond - Node.js at scale
Tom Croucher
 
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
Tom Croucher
 
Building a real life application in node js
fakedarren
 
Building servers with Node.js
ConFoo
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
Node.js in production
Felix Geisendörfer
 
Node js presentation
martincabrera
 
Introduction to node.js GDD
Sudar Muthu
 
Introduction to node.js
jacekbecela
 
Building your first Node app with Connect & Express
Christian Joudrey
 
Introduction to Node.js: What, why and how?
Christian Joudrey
 
Node.js - A practical introduction (v2)
Felix Geisendörfer
 
All aboard the NodeJS Express
David Boyer
 
Intro to Node.js (v1)
Chris Cowan
 
Node.js - Best practices
Felix Geisendörfer
 
Complete MVC on NodeJS
Hüseyin BABAL
 
Ad

Viewers also liked (7)

PPTX
Présentation de Node.js
Mickael Couzinet
 
PPTX
Introduction à Node.js
Sonam TCHEUTSEUN
 
PPTX
JavaScript on the server - Node.js
Rody Middelkoop
 
PDF
Node.js Module Resolution by visual example
Jeff Kunkle
 
PDF
Node.js從無到有 基本課程
Simon Su
 
PPTX
Autour de Node.js - TechConf#3
Luc Juggery
 
PDF
Node.js et les nouvelles technologies javascript
Khalid Jebbari
 
Présentation de Node.js
Mickael Couzinet
 
Introduction à Node.js
Sonam TCHEUTSEUN
 
JavaScript on the server - Node.js
Rody Middelkoop
 
Node.js Module Resolution by visual example
Jeff Kunkle
 
Node.js從無到有 基本課程
Simon Su
 
Autour de Node.js - TechConf#3
Luc Juggery
 
Node.js et les nouvelles technologies javascript
Khalid Jebbari
 
Ad

Similar to A language for the Internet: Why JavaScript and Node.js is right for Internet Application (20)

PDF
Introduction to Node.js
Richard Lee
 
PDF
Introduction to Nodejs
Gabriele Lana
 
DOCX
Node js getting started
Pallavi Srivastava
 
PDF
About Node.js
Artemisa Yescas Engler
 
PPTX
httpmodule in java script all methods.pptx
sontinenianuradha
 
PDF
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
PDF
Nodejsexplained 101116115055-phpapp02
Sunny Gupta
 
PPT
nodejs_at_a_glance.ppt
WalaSidhom1
 
PPT
nodejs_at_a_glance, understanding java script
mohammedarshadhussai4
 
PPTX
Building and Scaling Node.js Applications
Ohad Kravchick
 
PPT
Node.js
Pravin Mishra
 
PPTX
Introduction to Node.js
Vikash Singh
 
KEY
Playing With Fire - An Introduction to Node.js
Mike Hagedorn
 
PDF
Introduction to Node.js
Somkiat Puisungnoen
 
PDF
Web Server.pdf
Bareen Shaikh
 
PPTX
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
PDF
Basic Understanding and Implement of Node.js
Gary Yeh
 
PPTX
Node.js Workshop - Sela SDP 2015
Nir Noy
 
PPTX
A slightly advanced introduction to node.js
Sudar Muthu
 
PDF
Intro to node.js - Ran Mizrahi (27/8/2014)
Ran Mizrahi
 
Introduction to Node.js
Richard Lee
 
Introduction to Nodejs
Gabriele Lana
 
Node js getting started
Pallavi Srivastava
 
About Node.js
Artemisa Yescas Engler
 
httpmodule in java script all methods.pptx
sontinenianuradha
 
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh
 
Nodejsexplained 101116115055-phpapp02
Sunny Gupta
 
nodejs_at_a_glance.ppt
WalaSidhom1
 
nodejs_at_a_glance, understanding java script
mohammedarshadhussai4
 
Building and Scaling Node.js Applications
Ohad Kravchick
 
Node.js
Pravin Mishra
 
Introduction to Node.js
Vikash Singh
 
Playing With Fire - An Introduction to Node.js
Mike Hagedorn
 
Introduction to Node.js
Somkiat Puisungnoen
 
Web Server.pdf
Bareen Shaikh
 
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
Basic Understanding and Implement of Node.js
Gary Yeh
 
Node.js Workshop - Sela SDP 2015
Nir Noy
 
A slightly advanced introduction to node.js
Sudar Muthu
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Ran Mizrahi
 

More from Tom Croucher (20)

PDF
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
KEY
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
KEY
Using Node.js to improve the performance of Mobile apps and Mobile web
Tom Croucher
 
KEY
Creating the Internet of Things with JavaScript - Fluent Conf
Tom Croucher
 
KEY
Using Node.js to make HTML5 work for everyone
Tom Croucher
 
PDF
Lessons from a coding veteran - Web Directions @Media
Tom Croucher
 
KEY
Multi-tiered Node Architectures - JSConf 2011
Tom Croucher
 
PDF
How to stop writing spaghetti code
Tom Croucher
 
PDF
Doing Horrible Things with DNS - Web Directions South
Tom Croucher
 
PDF
Doing Horrible Things to DNS in the Name of Science - SF Performance Meetup
Tom Croucher
 
KEY
How to stop writing spaghetti code - JSConf.eu 2010
Tom Croucher
 
PDF
Sf perf
Tom Croucher
 
PDF
Server Side JavaScript - You ain't seen nothing yet
Tom Croucher
 
PDF
JavaScript Everywhere! Creating a 100% JavaScript web stack
Tom Croucher
 
PDF
Mobile Data: How to avoid the latency trap - SWDC 2010
Tom Croucher
 
KEY
Let's run JavaScript Everywhere
Tom Croucher
 
KEY
Pirate yql
Tom Croucher
 
KEY
YQL Tutorial
Tom Croucher
 
PPT
How to avoid the latency trap and lessons about software design
Tom Croucher
 
PPT
Unicorns Metrics and Hotsauce - Lessons about Evangelism from the Yahoo! Deve...
Tom Croucher
 
Using Node.js to Build Great Streaming Services - HTML5 Dev Conf
Tom Croucher
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Tom Croucher
 
Using Node.js to improve the performance of Mobile apps and Mobile web
Tom Croucher
 
Creating the Internet of Things with JavaScript - Fluent Conf
Tom Croucher
 
Using Node.js to make HTML5 work for everyone
Tom Croucher
 
Lessons from a coding veteran - Web Directions @Media
Tom Croucher
 
Multi-tiered Node Architectures - JSConf 2011
Tom Croucher
 
How to stop writing spaghetti code
Tom Croucher
 
Doing Horrible Things with DNS - Web Directions South
Tom Croucher
 
Doing Horrible Things to DNS in the Name of Science - SF Performance Meetup
Tom Croucher
 
How to stop writing spaghetti code - JSConf.eu 2010
Tom Croucher
 
Sf perf
Tom Croucher
 
Server Side JavaScript - You ain't seen nothing yet
Tom Croucher
 
JavaScript Everywhere! Creating a 100% JavaScript web stack
Tom Croucher
 
Mobile Data: How to avoid the latency trap - SWDC 2010
Tom Croucher
 
Let's run JavaScript Everywhere
Tom Croucher
 
Pirate yql
Tom Croucher
 
YQL Tutorial
Tom Croucher
 
How to avoid the latency trap and lessons about software design
Tom Croucher
 
Unicorns Metrics and Hotsauce - Lessons about Evangelism from the Yahoo! Deve...
Tom Croucher
 

Recently uploaded (20)

PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Architecture of the Future (09152021)
EdwardMeyman
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Doc9.....................................
SofiaCollazos
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Software Development Methodologies in 2025
KodekX
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Architecture of the Future (09152021)
EdwardMeyman
 

A language for the Internet: Why JavaScript and Node.js is right for Internet Application

  • 1. A language for the Internet Why JavaScript and Node.js is right for Internet Applications Tom Hughes-Croucher @sh1mmer
  • 2. Me
  • 5. Scalable Server-Side Code with JavaScript Node Up and Running Tom Hughes-Croucher
  • 15. More features More users More devices More data
  • 16. Cost Stuff
  • 17. How do we cope with the increase in demand?
  • 20. Browser Server Spidering... The Web
  • 22. Browser Front-end Server Database
  • 23. Client → Server Computation
  • 24. Client → Server Server → DB Computation Computation
  • 37. Node.js? • Server Side JavaScript runtime • Built on top of V8 JavaScript engine from Google Chrome • Non-blocking I/O APIs • Easy to extend APIs and modules
  • 39. $Enki:~ $ node >3>2>1 false > true == 1 true > true === 1 false
  • 40. > console.log('Hello World'); Hello World > .help .clear Break, and also clear the local context. .exit Exit the prompt .help Show repl options > .clear Clearing context... > .exit Enki:~ $
  • 41. Enki:~ $ node > var foo = "bar"; > foo; 'bar' > .clear Clearing context... > foo ReferenceError: foo is not defined at [object Context]:1:1 at Interface.<anonymous> (repl:98:19) at Interface.emit (events:27:15) at Interface._ttyWrite (readline:295:12) at Interface.write (readline:132:30) at Stream.<anonymous> (repl:79:9) at Stream.emit (events:27:15) at IOWatcher.callback (net:489:16)
  • 42. var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }).listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/');
  • 43. var http = require('http'); //include the http library
  • 44. http.createServer(function (req, res) { }).listen(8124, "127.0.0.1"); //create an http server //when ‘stuff’ happens call this anonymous function //listen on port 8124 of the IP 127.0.0.1
  • 45. http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }) //when ‘stuff’ happens my function fires //I get a request object and a response object //I write to the response object header //HTTP status 200 and content-type ‘text/plain’ //close the response with the body: //Hello World
  • 46. console.log('Server running at http://127.0.0.1:8124/'); //write Server is running at http://127.0.0.1:8124/ //to the console
  • 47. Why is Node.js suited to Internet Apps?
  • 49. What is the event loop?
  • 54. var http = require('http'); server = http.createServer(); server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/');
  • 55. var http = require('http'); server = http.createServer(); server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 1. Evaluate 'Main'
  • 56. var http = require('http'); server = http.createServer(); server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 1. variables: http -> http module server -> http server listeners: server.request -> function
  • 57. var http = require('http'); server = http.createServer(); * server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 2. Event Loop
  • 58. var http = require('http'); server = http.createServer(); * server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 2. Do we have active listeners? listeners: server.request -> function Yes! Wait for listeners.
  • 59. var http = require('http'); server = http.createServer(); server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 3. Event Calls
  • 60. var http = require('http'); server = http.createServer(); server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 3. 'request' is called. Since listeners: server.request -> function Call function
  • 61. var http = require('http'); server = http.createServer(); server.on('request', function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello Worldn'); }); server.listen(8124, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8124/'); Step 3. Loop! (go to Step 2.)
  • 64. EE = require('events').EventEmitter; ee = new EE(); die = false; ee.on('die', function() { die = true; }); setTimeout(function() { ee.emit('die'); }, 100); while(!die) { } console.log('done');
  • 65. Why non-blocking matters
  • 66. var result = db.query("select * from T"); // use result
  • 69. "Blocking" is as bad as stopping
  • 70. Event Loop vs. Threads
  • 71. PHP 8mb 8gb ram 8000/8 = 1000 ~1000 users per machine
  • 72. Node.js TCP = 2kb HTTP = 6kb 8gb ram 8000/0.006 = 1.3m 1.3m/2 ~ 650k users
  • 73. Apache vs NGINX concurrency × reqs/sec http://blog.webfaction.com/a-little-holiday-present
  • 74. Apache vs NGINX concurrency × memory http://blog.webfaction.com/a-little-holiday-present
  • 75. Node.js is designed for communication, just like your applications
  • 76. Thanks! Questions? Tom Hughes-Croucher @sh1mmer

Editor's Notes