Created
October 9, 2019 18:13
-
-
Save rcabreu/f8196128f9faf99523bbd0ea65b064bb to your computer and use it in GitHub Desktop.
Only reacts to POST requests. Prints request body in stdout.
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
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