Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Last active November 30, 2024 04:32
Show Gist options
  • Save magnetikonline/ee8f536631f3c3c508182a7c6a0aedf5 to your computer and use it in GitHub Desktop.
Save magnetikonline/ee8f536631f3c3c508182a7c6a0aedf5 to your computer and use it in GitHub Desktop.
Node.js HTTP echo server.
import http from 'node:http';
const server = http.createServer();
server.on('request',(req,resp) => {
const body = [];
req.on('data',function(chunk) {
body.push(chunk);
});
req.on('end',function() {
console.log(`>> Request: ${req.method} ${req.url}`);
console.log('>> HTTP headers');
console.log(req.headers);
console.log('>> Body');
console.log(Buffer.concat(body).toString());
console.log('\n');
resp.end();
});
}).listen(8083);
{
"type": "module"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment