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
[codesyntax lang=”javascript”]
// blocking result = query('select * from t'); some_function(result); // non-blocking query('select * from t', function(result) { // callback });
[/codesyntax]
3. Amazing Video by Ryan Dahl – Introduction to NodeJS
4. Download and install
[codesyntax lang=”bash”]
$ 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
[/codesyntax]
5. Make the doc and read (optional)
[codesyntax lang=”bash”]
$ make doc $ man doc/node.1
[/codesyntax]
6. Server side test script
[codesyntax lang=”javascript”]
// hello_world.js : var sys = require('sys'); setTimeout(function() { sys.puts('world'); }, 2000); sys.puts('hello');
[/codesyntax]
7. “hello world”
[codesyntax lang=”bash”]
$ /usr/local/node/bin/node hello_world.js
[/codesyntax]
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