Ejercicio 1. Mi primer servidor HTTP en node.js

ej01.js:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hola mundo\n');
}).listen(2012, "127.0.0.1");

console.log('Servidor corriendo en http://127.0.0.1:2012/');

Ejecución de ej01.js:

jordi@jordi-Aspire-5810T:~/nodes$ node ej01.js &
[1] 2922
jordi@jordi-Aspire-5810T:~/nodes$ Servidor corriendo en http://127.0.0.1:2012/
 
jordi@jordi-Aspire-5810T:~/nodes$ curl -i http://localhost:2012
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: keep-alive
Transfer-Encoding: chunked
 
Hola mundo
jordi@jordi-Aspire-5810T:~/nodes$