Created
April 20, 2015 12:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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