12 de noviembre de 2011

Hola Mundo en Node.js / Ubuntu 11.10

HOWTO para instalar Node.js en Ubuntu 11.10

Instalando node.js

Se instalará node.js en tu carpeta de usuario: ~/local/bin
La versión a instalar será la 0.4.7, para luego poder deployarlo en Heroku

$ sudo apt-get install libssl-dev build-essential g++ curl git

$ mkdir ~/local
$ echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc
$ export NODE_VERSION='0.4.7'

$ wget http://nodejs.org/dist/node-v$NODE_VERSION.tar.gz
$ tar xvfz node-v$NODE_VERSION.tar.gz
$ cd node-v$NODE_VERSION
$ ./configure --prefix=~/local --without-ssl
$ make install
$ cd ~

Instalando npm

Npm es el gestor de paquetes de node.js.

$ curl http://npmjs.org/install.sh | sh

Probando

Creamos el fichero test.js con el contenido.


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/');

Ejecutamos...


$ node test.js 
Server running at http://127.0.0.1:1337/


Referencias:

Update

Para instalar la última versión actual de node (v0.6.3), sustituimos:

$ export NODE_VERSION='0.4.7'


por 


$ export NODE_VERSION='0.6.3'


y


$ wget http://nodejs.org/dist/node-v$NODE_VERSION.tar.gz


por


$ wget http://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION.tar.gz

No hay comentarios:

Publicar un comentario