Skip to content

Instantly share code, notes, and snippets.

@rcabreu
Created October 9, 2019 18:13
Show Gist options
  • Save rcabreu/f8196128f9faf99523bbd0ea65b064bb to your computer and use it in GitHub Desktop.
Save rcabreu/f8196128f9faf99523bbd0ea65b064bb to your computer and use it in GitHub Desktop.
Only reacts to POST requests. Prints request body in stdout.
const http = require('http')
const server = http.createServer(function(request, response) {
console.dir(request.param)
if (request.method == 'POST') {
console.log('POST')
var body = ''
request.on('data', function(data) {
body += data
console.log('Partial body: ' + body)
})
request.on('end', function() {
console.log('Body: ' + body)
response.writeHead(200, {'Content-Type': 'text/html'})
response.end('post received')
})
}
})
const port = 1234
const host = '0.0.0.0'
server.listen(port, host)
console.log(`Listening at http://${host}:${port}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment