NodeJS: Quick dev server

I'm on a nice project where I need to develop a kind of proxy in NodeJS. When you work to forward data after possible filtering or transformation, it's never too easy to quickly set up an environment in order to test your on-going development.

Using NodeJS, I extended my colleague very small HTTP server that just returns a 201 HTTP code and prints the request body in the console:

// debug-server.js
var http = require('http');
var port = process.env.PORT || 8080;
var host = '127.0.0.1';

http.createServer(function (request, response) {
    // console.log(request.headers);
    request.pipe(process.stdout);
    request.on('end', function () {
        process.stdout.write('\n');
    });
    response.writeHead(201);
    response.end();
}).listen(port, host, 511, function () {
    console.log('Started to listen on ' + host + ':' + port);
});

That's it. No need for no dependency, just have NodeJS installed and run it:

$ node debug-server.js
Started to listen on 127.0.0.1:8080

If you need to specify another port:

$ PORT=6677 node debug-server.js
Started to listen on 127.0.0.1:6677

Have fun, happy coding :)