Skip to content

Instantly share code, notes, and snippets.

@bszwej
Last active April 26, 2024 05:22
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save bszwej/62c327d773051816ed4949fd40c82c74 to your computer and use it in GitHub Desktop.
Save bszwej/62c327d773051816ed4949fd40c82c74 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);
@handre
Copy link

handre commented Feb 6, 2020

Thanks!

@wedneyyuri
Copy link

Thanks!

@un4ckn0wl3z
Copy link

Thanks! it's useful for temporary monitor http logs.

@cognivore
Copy link

Thanks! It's useful for setting up captcha!

@m0zgen
Copy link

m0zgen commented Jan 28, 2022

Thx, man 👍

@Andrebtk
Copy link

Thanks work like a charm

@snatvb
Copy link

snatvb commented Jul 19, 2022

thanks!

@mightybo28
Copy link

Thanks

@lukaspechar
Copy link

Smashing!

@ephrin
Copy link

ephrin commented Mar 23, 2023

Nice!

@Aschen
Copy link

Aschen commented Oct 15, 2023

The oneliner version, just copy past in your terminal:

node -e "const h = require('http');const s = h.createServer();const l = console.log;s.on('request', (rq, rs) => {let b = [];rq.on('data', (c) => {b.push(c);}).on('end', () => {b = Buffer.concat(b).toString();l('==== '+rq.method+' '+rq.url);l('> Headers');l(rq.headers);l('> Body');l(b);rs.end();});}).listen(8000);"

@meenabassem
Copy link

The oneliner version, just copy past in your terminal:

node -e "const h = require('http');const s = h.createServer();const l = console.log;s.on('request', (rq, rs) => {let b = [];rq.on('data', (c) => {b.push(c);}).on('end', () => {b = Buffer.concat(b).toString();l('==== '+rq.method+' '+rq.url);l('> Headers');l(rq.headers);l('> Body');l(b);rs.end();});}).listen(8000);"

Many thanks for this bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment