Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Node.js script. Spits out the headers of a request - useful for basic remote request testing
var http = require('http');
var qs = require('querystring');
/* Host / Port configuration.
Defaults to listening on all interfaces, port 80.
*/
var host = "0.0.0.0";
var port = 80;
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello world!");
console.log("\n")
console.log(req.method + ": " + req.headers.host + req.url)
console.log(req["headers"]);
if (req.method in {'POST':'', 'PUT':'', 'DELETE':''}) {
var body = ''
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
console.log(qs.parse(body));
});
}
}).listen(port, host);
console.log('Server running');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment