Skip to content

Instantly share code, notes, and snippets.

@jrusev
Last active February 16, 2018 12:45
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 jrusev/461aa946787c62976de089af6062f61d to your computer and use it in GitHub Desktop.
Save jrusev/461aa946787c62976de089af6062f61d to your computer and use it in GitHub Desktop.
var http = require('http');
var port = 1234;
http.createServer(function (req, resp) {
var body = [];
req.on('data', function (chunk) { body.push(chunk); });
req.on('end', function () {
body = Buffer.concat(body).toString();
console.log({headers: req.headers, method: req.method, body: body});
resp.writeHead(200, {'Content-Type': 'text/plain'});
resp.end('OK');
});
}).listen(port);
console.log('Server listening on port', port);
// $ node server.js
// $ curl -i localhost:1234
// $ curl -i -X POST localhost:1234 -H 'Content-Type: application/json' -d '{}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment