Skip to content

Instantly share code, notes, and snippets.

@jrusev jrusev/server.js
Last active Feb 16, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.