Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Created June 7, 2012 13:23
Show Gist options
  • Select an option

  • Save sunnygleason/2888796 to your computer and use it in GitHub Desktop.

Select an option

Save sunnygleason/2888796 to your computer and use it in GitHub Desktop.
node.js http servers suitable for debugging
var http = require('http');
http.createServer(function (req, res) {
console.log(req);
var body = '';
req.on('data', function (data) { body += data; });
req.on('end', function () {
console.log('body', body);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('service the first\n');
});
}).listen(9090, "127.0.0.1");
http.createServer(function (req, res) {
console.log(req);
res.writeHead(200, {'Content-Type': 'text/plain'});
req.on('end', function () {
console.log('body', body);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('service the second\n');
});
).listen(9190, "127.0.0.1");
console.log('Server running at http://127.0.0.1/ port 9090 and 9190');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment