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
(@sh1mmer)
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
Scalable Server-Side Code with JavaScript




Node                     Up and Running




                        Tom Hughes-Croucher
A brief aside.
A small lecture on
     biology
The common tree shrew
Diana Monkey
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
Back to your feature
   presentation.
Internet?
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
She’s called Eleanor
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
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
Computation

                 Database
Computational Computing

Client → Server




                  Computation
Internet Computing

Client → Server   Server → DB




         Computation     Computation
“Traditional” Approach
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
Server
Request
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
U L L
F
Event-driven Approach
Place-
holder
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
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 Applications
What is the event
      loop?
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
Multi-tasking,
one thing at a time.
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
A language for the Internet: Why JavaScript and Node.js is right for Internet Applications
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 Applications
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 Applications
"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!
Follow me @sh1mmer


Tom Hughes-Croucher
@sh1mmer

More Related Content

KEY
A language for the Internet: Why JavaScript and Node.js is right for Internet...
PDF
How To Electrocute Yourself using the Internet
KEY
A million connections and beyond - Node.js at scale
PDF
Nodejs Explained with Examples
PDF
Building servers with Node.js
PDF
Node.js - A Quick Tour
PPTX
introduction to node.js
KEY
Writing robust Node.js applications
A language for the Internet: Why JavaScript and Node.js is right for Internet...
How To Electrocute Yourself using the Internet
A million connections and beyond - Node.js at scale
Nodejs Explained with Examples
Building servers with Node.js
Node.js - A Quick Tour
introduction to node.js
Writing robust Node.js applications

What's hot (20)

KEY
node.js: Javascript's in your backend
KEY
Introduction to node.js
PDF
Server Side Event Driven Programming
PPTX
Java script at backend nodejs
PDF
Original slides from Ryan Dahl's NodeJs intro talk
PPTX
Nodejs intro
PPTX
Introduction to Node js
PPTX
Intro to Node.js (v1)
PPTX
Introduction Node.js
PPT
RESTful API In Node Js using Express
KEY
OSCON 2011 - Node.js Tutorial
PPTX
Node.js Patterns for Discerning Developers
PPTX
bootstrapping containers with confd
PDF
Introduction to Node.js: What, why and how?
PPT
Node js presentation
PDF
Non-blocking I/O, Event loops and node.js
PPTX
Introduction to node.js GDD
PDF
VCL template abstraction model and automated deployments to Fastly
PDF
NodeJS for Beginner
ODP
Introduce about Nodejs - duyetdev.com
node.js: Javascript's in your backend
Introduction to node.js
Server Side Event Driven Programming
Java script at backend nodejs
Original slides from Ryan Dahl's NodeJs intro talk
Nodejs intro
Introduction to Node js
Intro to Node.js (v1)
Introduction Node.js
RESTful API In Node Js using Express
OSCON 2011 - Node.js Tutorial
Node.js Patterns for Discerning Developers
bootstrapping containers with confd
Introduction to Node.js: What, why and how?
Node js presentation
Non-blocking I/O, Event loops and node.js
Introduction to node.js GDD
VCL template abstraction model and automated deployments to Fastly
NodeJS for Beginner
Introduce about Nodejs - duyetdev.com
Ad

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

PDF
Introduction to Nodejs
PDF
Introduction to Node.js
PPTX
httpmodule in java script all methods.pptx
PDF
Nodejsexplained 101116115055-phpapp02
DOCX
Node js getting started
PDF
Web Server.pdf
PDF
About Node.js
PPT
Node.js
PPT
nodejs_at_a_glance.ppt
PPT
nodejs_at_a_glance, understanding java script
PPTX
Building and Scaling Node.js Applications
PPTX
Node.js web-based Example :Run a local server in order to start using node.js...
PPTX
Introduction to Node.js
PDF
Introduction to Node.js
KEY
Node.js - A practical introduction (v2)
KEY
Playing With Fire - An Introduction to Node.js
PDF
Node.js - async for the rest of us.
PPTX
Scalable network applications, event-driven - Node JS
PPTX
Node.js Workshop - Sela SDP 2015
PPTX
Intsllation & 1st program nodejs
Introduction to Nodejs
Introduction to Node.js
httpmodule in java script all methods.pptx
Nodejsexplained 101116115055-phpapp02
Node js getting started
Web Server.pdf
About Node.js
Node.js
nodejs_at_a_glance.ppt
nodejs_at_a_glance, understanding java script
Building and Scaling Node.js Applications
Node.js web-based Example :Run a local server in order to start using node.js...
Introduction to Node.js
Introduction to Node.js
Node.js - A practical introduction (v2)
Playing With Fire - An Introduction to Node.js
Node.js - async for the rest of us.
Scalable network applications, event-driven - Node JS
Node.js Workshop - Sela SDP 2015
Intsllation & 1st program nodejs
Ad

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
PDF
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
KEY
How to stop writing spaghetti code - JSConf.eu 2010
PDF
Sf perf
PDF
Node.js and How JavaScript is Changing Server Programming
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
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
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
How to stop writing spaghetti code - JSConf.eu 2010
Sf perf
Node.js and How JavaScript is Changing Server Programming
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

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Big Data Technologies - Introduction.pptx
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Review of recent advances in non-invasive hemoglobin estimation
Big Data Technologies - Introduction.pptx
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

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

  • 1. A language for the Internet Why JavaScript and Node.js is right for Internet Applications Tom Hughes-Croucher @sh1mmer
  • 5. Scalable Server-Side Code with JavaScript Node Up and Running Tom Hughes-Croucher
  • 6. A brief aside. A small lecture on biology
  • 11. Back to your feature presentation.
  • 21. More features More users More devices More data
  • 22. Cost Stuff
  • 23. How do we cope with the increase in demand?
  • 26. Browser Server Spidering... The Web
  • 28. Browser Front-end Server Computation Database
  • 30. Internet Computing Client → Server Server → DB Computation Computation
  • 43. 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
  • 45. $Enki:~ $ node >3>2>1 false > true == 1 true > true === 1 false
  • 46. > 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:~ $
  • 47. 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)
  • 48. 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/');
  • 49. var http = require('http'); //include the http library
  • 50. 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
  • 51. 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
  • 52. 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
  • 53. Why is Node.js suited to Internet Apps?
  • 55. What is the event loop?
  • 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/');
  • 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 1. Evaluate 'Main'
  • 62. 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
  • 63. 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
  • 64. 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.
  • 65. 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
  • 66. 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
  • 67. 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.)
  • 70. 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');
  • 71. Why non-blocking matters
  • 72. var result = db.query("select * from T"); // use result
  • 75. "Blocking" is as bad as stopping
  • 76. Event Loop vs. Threads
  • 77. PHP 8mb 8gb ram 8000/8 = 1000 ~1000 users per machine
  • 78. Node.js TCP = 2kb HTTP = 6kb 8gb ram 8000/0.006 = 1.3m 1.3m/2 ~ 650k users
  • 79. Apache vs NGINX concurrency × reqs/sec http://blog.webfaction.com/a-little-holiday-present
  • 80. Apache vs NGINX concurrency × memory http://blog.webfaction.com/a-little-holiday-present
  • 81. Node.js is designed for communication, just like your applications
  • 83. Follow me @sh1mmer Tom Hughes-Croucher @sh1mmer

Editor's Notes