Skip to content

Instantly share code, notes, and snippets.

@sagaban
Forked from bszwej/echo.js
Created June 26, 2024 17:54
Show Gist options
  • Save sagaban/c07095d5c7912a89fa38702edd5899ea to your computer and use it in GitHub Desktop.
Save sagaban/c07095d5c7912a89fa38702edd5899ea to your computer and use it in GitHub Desktop.
Pure Node.js echo server, that logs all incoming http requests (method, path, headers, body).
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