Skip to content

Instantly share code, notes, and snippets.

@duggan
Created March 8, 2012 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duggan/2002769 to your computer and use it in GitHub Desktop.
Save duggan/2002769 to your computer and use it in GitHub Desktop.
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