Node.js

Node.js

Edward O’Connor
SD Ruby

Happy Canada Day!

Node.js is an event-driven networking engine for JavaScript.

Think eventmachine, but for V8, not Ruby.

Watch the video.

Grab it from github

# http://github.com/ry/node
./configure
make
sudo make install

Give it a spin

var http = require('http');
http.createServer(function (req, res) {
  res.sendHeader(200, {
    'Content-Type': 'text/plain'
  });
  res.sendBody('Hello, world!');
  res.finish();
}).listen(8000);
// This bit sure looks familiar…
http.createServer(function (req, res) {
  res.sendHeader(200, {
    'Content-Type': 'text/plain'
  });
  res.sendBody('Hello, world!');
  res.finish();
}).listen(8000);
# Just like Rack
def simple_app(env)
  [200,
   {"Content-Type" => "text/plain"},
   ['Hello, world!\n']]
end
# but async

Rack works because it’s so easy to compose middleware & apps.

// JavaScript lends itself to
// functional composition

function foo(bar) {
    return function() {
        // … do something, then …
        bar.apply(this, arguments);
    }
}

…and JS programmers are already used to evented programming.

not just fast à la eventmachine, but natural.

formidable: (~500mb/sec) multipart form handler

aredridel/html5 & tmpvar/jsdom

Server-side DOM scripting…

Same scripts can run in-browser too!

Not just for HTTP & HTML—for all sorts of networking tasks.

There's a cat…

…in a tuxedo…

surfing

Evented programming makes protocol mashups easy.

JavaScript is not just for browsers any more.

Get involved!
fork it · talk about it

thank you · cc by-sa 3.0