Saturday, 9 March 2013

install node.js

install dependencies to retrieve, build and browse.
            
$ sudo apt-get install g++ curl libssl-dev apache2-utils
$ sudo apt-get install git-core

Retrieve from repository.
            
$ git clone git://github.com/ry/node.git

Build node.js.
$ cd node
$ ./configure
$ make
$ sudo make install

Create ‘helloworld.js’.
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

Run ‘helloworld.js’.
            
$ node helloworld.js
Server running at http://127.0.0.1:1337/

Browse to verify

            
http://127.0.0.1:1337/

No comments:

Post a Comment