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
KEY
Writing robust Node.js applications
PPTX
Java script at backend nodejs
PDF
Non-blocking I/O, Event loops and node.js
PPT
RESTful API In Node Js using Express
KEY
node.js: Javascript's in your backend
PDF
Node.js and How JavaScript is Changing Server Programming
KEY
OSCON 2011 - Node.js Tutorial
Node.js - A Quick Tour
Writing robust Node.js applications
Java script at backend nodejs
Non-blocking I/O, Event loops and node.js
RESTful API In Node Js using Express
node.js: Javascript's in your backend
Node.js and How JavaScript is Changing Server Programming
OSCON 2011 - Node.js Tutorial

What's hot (20)

PPTX
introduction to node.js
PDF
Server Side Event Driven Programming
PDF
Nodejs Explained with Examples
KEY
A million connections and beyond - Node.js at scale
PDF
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
KEY
Building a real life application in node js
PDF
Building servers with Node.js
KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PDF
Node.js in production
PPT
Node js presentation
PPTX
Introduction to node.js GDD
KEY
Introduction to node.js
PPT
Building your first Node app with Connect & Express
PDF
Introduction to Node.js: What, why and how?
PDF
KEY
Node.js - A practical introduction (v2)
PDF
All aboard the NodeJS Express
PPTX
Intro to Node.js (v1)
KEY
Node.js - Best practices
PDF
Complete MVC on NodeJS
introduction to node.js
Server Side Event Driven Programming
Nodejs Explained with Examples
A million connections and beyond - Node.js at scale
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
Building a real life application in node js
Building servers with Node.js
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Node.js in production
Node js presentation
Introduction to node.js GDD
Introduction to node.js
Building your first Node app with Connect & Express
Introduction to Node.js: What, why and how?
Node.js - A practical introduction (v2)
All aboard the NodeJS Express
Intro to Node.js (v1)
Node.js - Best practices
Complete MVC on NodeJS
Ad

Viewers also liked (7)

PPTX
Présentation de Node.js
PPTX
Introduction à Node.js
PPTX
JavaScript on the server - Node.js
PDF
Node.js Module Resolution by visual example
PDF
Node.js從無到有 基本課程
PPTX
Autour de Node.js - TechConf#3
PDF
Node.js et les nouvelles technologies javascript
Présentation de Node.js
Introduction à Node.js
JavaScript on the server - Node.js
Node.js Module Resolution by visual example
Node.js從無到有 基本課程
Autour de Node.js - TechConf#3
Node.js et les nouvelles technologies javascript
Ad

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

PPTX
Intro to Node
PDF
Nodejsexplained 101116115055-phpapp02
PDF
PPT
Node.js
PPTX
Node.js web-based Example :Run a local server in order to start using node.js...
PDF
Original slides from Ryan Dahl's NodeJs intro talk
PDF
Introduction to Node.js
PDF
Node.js introduction
PDF
Web Server.pdf
PPTX
GeekCampSG - Nodejs , Websockets and Realtime Web
PPTX
Scalable network applications, event-driven - Node JS
PDF
Event driven programming -- Node.JS
PPTX
Node.js Workshop - Sela SDP 2015
KEY
Node.js
PDF
8 Minutes On Rack
PDF
soft-shake.ch - Hands on Node.js
PPTX
Node.js System: The Approach
PDF
Introduction to Node.js
PPTX
Intro to node and mongodb 1
KEY
Message in a Bottle
Intro to Node
Nodejsexplained 101116115055-phpapp02
Node.js
Node.js web-based Example :Run a local server in order to start using node.js...
Original slides from Ryan Dahl's NodeJs intro talk
Introduction to Node.js
Node.js introduction
Web Server.pdf
GeekCampSG - Nodejs , Websockets and Realtime Web
Scalable network applications, event-driven - Node JS
Event driven programming -- Node.JS
Node.js Workshop - Sela SDP 2015
Node.js
8 Minutes On Rack
soft-shake.ch - Hands on Node.js
Node.js System: The Approach
Introduction to Node.js
Intro to node and mongodb 1
Message in a Bottle

More from Tom Croucher (20)

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

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PPT
Teaching material agriculture food technology
PDF
Modernizing your data center with Dell and AMD
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
Teaching material agriculture food technology
Modernizing your data center with Dell and AMD
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf

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