Skip to content

Instantly share code, notes, and snippets.

@vasanthk
Created April 20, 2015 12:13
Show Gist options
  • Save vasanthk/e03e530525505c57d4e0 to your computer and use it in GitHub Desktop.
Save vasanthk/e03e530525505c57d4e0 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. 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