Skip to content

Instantly share code, notes, and snippets.

@sdesalas
Forked from bszwej/echo.js
Created August 3, 2022 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdesalas/3139baad5b6a388118507d7b5f4a7d8b to your computer and use it in GitHub Desktop.
Save sdesalas/3139baad5b6a388118507d7b5f4a7d8b 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