SlideShare a Scribd company logo
A practical introduction



Felix Geisendörfer                         Øredev 09.11.2011 (v1)
@felixge

Twitter / GitHub / IRC


    Felix Geisendörfer
     (Berlin, Germany)
Audience?
JavaScript?
Node.js?
History
Feb 16, 2009




Ryan Dahl starts the node project (first commit)
~June, 2009




Discovered node.js (v0.0.6)
transloadit.com
Nodejs a-practical-introduction-oredev
Core Contributor

                    &

              Module Author



node-mysql                      node-formidable



                                  + 30 other modules
Sep 29, 2009




Isaac Schlueter starts the npm package manager
                  (first commit)
Nov 7, 2009




Ryan’s talk at JSConf.EU gets people excited about node
Today
#2
2nd most watched repository on GitHub
230 Contributors
0.6.0 was released 4 days ago (Nov 5)
Companies using node
• GitHub (for Downloads)
• Palm/HP (in WebOS)
• Yahoo! Mail
• Dow Jones & Company (for WJS social site)
• LinkedIn (Mobile Web App)
• Rackspace (Cloudkick monitoring)
• Voxxer (Push to Talk mobile app)
Nodejs a-practical-introduction-oredev
Installing
$ git clone 
git://github.com/joyent/node.git
$ cd node
$ git checkout v0.6.0
$ ./configure
$ sudo make install
     (windows users: download node.exe)
Hello World

hello.js
console.log('Hello World');



$ node hello.js
Hello World
Hello World (REPL)


 $ node
 > console.log('Hello World')
 Hello World
Http Server
http_server.js
var http = require('http');
var server = http.createServer(function(req, res) {
  res.end('Hi, how are you?');
});

server.listen(8080);


$ node http_server.js    $ curl localhost:8080
                         Hi, how are you?
“Come on, server side JS
 has been around since
        1996”
What is so special
 about node?
Speed
Speed

• Node can do ~6000 http requests / sec per
  CPU core (hello world, 1kb response,)


• It is no problem to handle thousands of
  concurrent connections which are
  moderately active
V8 JavaScript Engine
V8 JavaScript Engine

• Developed by Google in Aarhus, Denmark
  for Google Chrome


• Translates JavaScript in Assembly Code

• Crankshaft JIT (enabled in 0.6.0 by default)
V8 JavaScript Engine

• You can expect to be within ~10x of C
  performance usually


• Certain code can run within 2-3x of C

• Getting faster all the time
Non-Blocking I/O
Blocking I/O
read_file_sync.js

var fs = require('fs');
var one = fs.readFileSync('one.txt', 'utf-8');
console.log('Read file one');
var two = fs.readFileSync('two.txt', 'utf-8');
console.log('Read file two');


             $ node read_file_sync.js
             Read file one
             Read file two
Non-Blocking I/O
read_file_async.js
var fs = require('fs');
fs.readFile('one.txt', 'utf-8', function(err, data) {
  console.log('Read file one');
});
fs.readFile('two.txt', 'utf-8', function(err, data) {
  console.log('Read file two');
});

            $ node read_file_async.js
            Read file two
            Read file one
Nodejs a-practical-introduction-oredev
Blocking I/O

Read one.txt (20ms)

                                Read two.txt (10ms)

              Total duration (30ms)
Non-Blocking I/O

Read one.txt (20ms)

Read two.txt (10ms)

      Total duration (20ms)
Non-Blocking I/O
• Close to ideal for high concurrency / high
  throughput, single execution stack


• Forces you to write more efficient code by
  parallelizing your I/O


• Feels pretty much like AJAX in the browser
WebSockets
  (Push)
WebSockets

•   Persistent connection between browser/server


•   Very hard / awkward to do on traditional stacks


•   Hard to scale on traditional stacks
Socket.IO (community module)
       •   WebSocket

       •   Adobe® Flash® Socket

       •   AJAX long polling

       •   AJAX multipart streaming

       •   Forever Iframe

       •   JSONP Polling

Chooses most capable transport at runtime!
Streams
“Streams are to time as arrays are to space.”
                    -- Jed Schmidt @ JSConf.eu 2010
Streams in node.js

•   Readable


•   Writable


•   Both
Streams
var http = require('http');
var server = http.createServer(function(req, res) {
  req.on('data', console.log);
});
server.listen(8080);

$ node stream.js &
$ curl -F file=@stream.js localhost:8080
------------------------------41e92562223e
Content-Disposition: form-data; name="file"; filename
Content-Type: application/octet-stream

var http = require('http');
var server = http.createServer(function(req, res) {
Streams
var http = require('http');
var spawn = require('child_process').spawn;

http.createServer(function(req, res) {
  var params = req.url.split('/');
  var args = [params[1], '-resize', params[2], '-'];
  var convert = spawn('convert', args);

  convert.stdout.pipe(res);
}).listen(8080);
On Github


felixge/node-convert-example
NPM package manager
NPM
• Puts dependencies in the right place, then
  gets out of your way


• No modification of a global load path
  (require.paths is gone in 0.6.0)


• 4700+ Modules in npm, > 10 new
  modules / day
So what is node good
        for?
Use cases

• WebSockets/Push applications

• Proxying data streams

• Backend for single page apps
Use cases

• Spawning other programs (processes) to do
  work / IPC


• Parallelizing I/O
So what is node not
     good for?
Anti-Use cases
• Actual Realtime Systems

• Number crunching / huge in-memory
  datasets


• (CRUD apps)
Join the Community

• Mailing list (nodejs, nodejs-dev)

• IRC (#node.js) - 700+ User online
Thank you!
Questions?




   @felixge
Thank you!
Bonus Slide
What’s next?

• Domains

• Improved Stream API

More Related Content

PDF
Nodejs - Should Ruby Developers Care?
PDF
Nodejs - A quick tour (v5)
KEY
Node.js - As a networking tool
PDF
Nodejs - A-quick-tour-v3
KEY
Node.js - A practical introduction (v2)
PDF
Nodejs - A quick tour (v4)
PDF
Dirty - How simple is your database?
PDF
Node.js - A Quick Tour II
Nodejs - Should Ruby Developers Care?
Nodejs - A quick tour (v5)
Node.js - As a networking tool
Nodejs - A-quick-tour-v3
Node.js - A practical introduction (v2)
Nodejs - A quick tour (v4)
Dirty - How simple is your database?
Node.js - A Quick Tour II

What's hot (20)

PDF
Node.js in production
PDF
Nodejs - A quick tour (v6)
PDF
Node.js - A Quick Tour
PDF
How to Test Asynchronous Code (v2)
PDF
Move Over, Rsync
KEY
node.js: Javascript's in your backend
PDF
PDF
Building the Right Platform Architecture for Hadoop
PPTX
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
PDF
Server-Side JavaScript Developement - Node.JS Quick Tour
PDF
Node.js and How JavaScript is Changing Server Programming
PDF
CoreOS + Kubernetes @ All Things Open 2015
PPTX
introduction to node.js
PPTX
Shell Tips & Tricks
PDF
Nodejs Explained with Examples
KEY
NodeJS
PDF
Declare your infrastructure: InfraKit, LinuxKit and Moby
KEY
Introduction to NodeJS with LOLCats
PDF
Elasticsearch for Logs & Metrics - a deep dive
PDF
Openstack 簡介
Node.js in production
Nodejs - A quick tour (v6)
Node.js - A Quick Tour
How to Test Asynchronous Code (v2)
Move Over, Rsync
node.js: Javascript's in your backend
Building the Right Platform Architecture for Hadoop
Running High Performance & Fault-tolerant Elasticsearch Clusters on Docker
Server-Side JavaScript Developement - Node.JS Quick Tour
Node.js and How JavaScript is Changing Server Programming
CoreOS + Kubernetes @ All Things Open 2015
introduction to node.js
Shell Tips & Tricks
Nodejs Explained with Examples
NodeJS
Declare your infrastructure: InfraKit, LinuxKit and Moby
Introduction to NodeJS with LOLCats
Elasticsearch for Logs & Metrics - a deep dive
Openstack 簡介
Ad

Viewers also liked (8)

PDF
Node.js гэж юу вэ?
PPTX
Create simple api using node js
PDF
Getting Started with the Node.js LoopBack APi Framework
PDF
Top Node.js Metrics to Watch
PPTX
Building a Node.js API backend with LoopBack in 5 Minutes
PDF
Microservices with Node.js and RabbitMQ
PDF
NodeJS for Beginner
PPTX
Introduction to Node.js
Node.js гэж юу вэ?
Create simple api using node js
Getting Started with the Node.js LoopBack APi Framework
Top Node.js Metrics to Watch
Building a Node.js API backend with LoopBack in 5 Minutes
Microservices with Node.js and RabbitMQ
NodeJS for Beginner
Introduction to Node.js
Ad

Similar to Nodejs a-practical-introduction-oredev (20)

ODP
Introduce about Nodejs - duyetdev.com
PPT
Node js beginner
PPTX
PPTX
Beginners Node.js
PPTX
Node.js Workshop - Sela SDP 2015
PDF
Introduction to Node.js
PPTX
PPT
18_Node.js.ppt
PDF
Node.js for beginner
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
KEY
20120514 nodejsdublin
PPT
18_Node.js.ppt
PDF
Node.js introduction
PPTX
An overview of node.js
PPT
Introducción y comandos en NodeJS slodte
PPT
Introduction to node.js aka NodeJS
PDF
KEY
Playing With Fire - An Introduction to Node.js
PPTX
Introduction to node
PDF
Introduction to Node.js
Introduce about Nodejs - duyetdev.com
Node js beginner
Beginners Node.js
Node.js Workshop - Sela SDP 2015
Introduction to Node.js
18_Node.js.ppt
Node.js for beginner
Event-driven IO server-side JavaScript environment based on V8 Engine
20120514 nodejsdublin
18_Node.js.ppt
Node.js introduction
An overview of node.js
Introducción y comandos en NodeJS slodte
Introduction to node.js aka NodeJS
Playing With Fire - An Introduction to Node.js
Introduction to node
Introduction to Node.js

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
A Presentation on Artificial Intelligence
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Tartificialntelligence_presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Getting Started with Data Integration: FME Form 101
PDF
Approach and Philosophy of On baking technology
PDF
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
Spectral efficient network and resource selection model in 5G networks
SOPHOS-XG Firewall Administrator PPT.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25-Week II
Tartificialntelligence_presentation.pptx
Empathic Computing: Creating Shared Understanding
Getting Started with Data Integration: FME Form 101
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf

Nodejs a-practical-introduction-oredev