-
-
Save snowdence/b48ba61a34ff4f09d46fac029b24b351 to your computer and use it in GitHub Desktop.
Pure Node.js echo server, that logs all incoming http requests (method, path, headers, body).
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(); | |
server.on('request', (request, response) => { | |
let body = []; | |
request.on('data', (chunk) => { | |
body.push(chunk); | |
}).on('end', () => { | |
body = Buffer.concat(body).toString(); | |
console.log(`==== ${request.method} ${request.url}`); | |
console.log('> Headers'); | |
console.log(request.headers); | |
console.log('> Body'); | |
console.log(body); | |
response.end(); | |
}); | |
}).listen(8083); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment