Home > javascript > Node.js


I’ve heard a lot about node.js recently so I looked after it a bit. At the homepage of the project you can find a one-hour long video presentation of the project.

Node.js is a set of libraries on top of Google’s V8 Javascript engine, which is used in Chrome. V8 is a very high performance virtual machine. Node.js uses the greatness of V8 to do networking things. The focus is on doing networking correctly.


Hello World:

setTimeout(function() {
}, 2000)

It registers that the first function must be executed in 2 sec. and it goes on. It prints ‘hello’, then ‘world’ 2 sec. later. One very important thing: in node.js there is no blocking (like sleep()). The program exits when there is nothing else left to do.

Simple web server:

var http = require('http');

var s = http.createServer(function(req, res) {
    res.writeHead(200, {'content-type' : 'text/plain'});

    setTimeout(function() {
    }, 2000)


All these examples are from the introductory video. In the video there is also a TCP server. He also shows a simple chat server via TCP.

Under Ubuntu I already had a “node” command. According to “man node” it was something different so I removed it (sudo apt-get remove node).

Download the source from the HQ, extract it, then configure, make, sudo make install.

Start it with the command “node” and you get a prompt. Execute a script with “node file.js”.

Further reading

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: