Skip to content

Instantly share code, notes, and snippets.

@kyletolle
Created September 11, 2013 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyletolle/6530914 to your computer and use it in GitHub Desktop.
Save kyletolle/6530914 to your computer and use it in GitHub Desktop.
A simple http server that listens for POST events at port 9000 and will print out the data it receives. Tweak the statusCode if you want to return something else like 500. This is useful for setting up as the url for a webhook and viewing/verifying the data that gets sent to that URL.
var app = require('http').createServer(handler);
var statusCode = 200;
app.listen(9000);
function handler (req, res) {
var data = '';
if (req.method == "POST") {
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {
console.log('Received body data:');
console.log(data.toString());
});
}
res.writeHead(statusCode, {'Content-Type': 'text/plain'});
res.end();
}
console.log("Listening to port 9000");
console.log("Returning status code " + statusCode.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment