Introduction to NodeJS

1. What is node.js and what does it do?
Evented I/O for V8 JavaScript.
To provide a purely evented, non-blocking infrastructure to script highly concurrent programs.

2. Basic concept : blocking and non-blocking

// blocking
result = query('select * from t');
some_function(result);

// non-blocking
query('select * from t', function(result) {
    // callback
});


3. Amazing Video by Ryan Dahl – Introduction to NodeJS



4. Download and install

$ wget http://nodejs.org/dist/node-v0.2.6.tar.gz
$ tar zxf node-v0.2.6.tar.gz
$ cd node-v0.2.6
$ ./configure --prefix=/usr/local/node
$ make
$ make install


5. Make the doc and read (optional)
$ make doc
$ man doc/node.1


6. Server side test script

// hello_world.js :
var sys = require('sys');
setTimeout(function() {
    sys.puts('world');
}, 2000);
sys.puts('hello');


7. “hello world”
$ /usr/local/node/bin/node hello_world.js


8. Resources
Online chat room example written in node.js : https://github.com/ry/node_chat
NodeJS Quick Tour : Node-JS_Quick_Tour_V2.pdf
Slides from JSConf 2010 : jsconf2010.pdf

Posted in JavaScript | Tagged , | Leave a comment