Skip to content

Instantly share code, notes, and snippets.

@guimello
Created June 6, 2019 17:04
Show Gist options
  • Save guimello/e661e2824f6225891eabdfa8760f989d to your computer and use it in GitHub Desktop.
Save guimello/e661e2824f6225891eabdfa8760f989d to your computer and use it in GitHub Desktop.
Simple request logger server
const http = require("http");
const port = 8081;
const s = http.createServer();
s.on("request", (request, response) => {
response.writeHead(200);
console.log({
headers: request.headers,
method: request.method,
url: request.url,
when: new Date().toLocaleString(),
});
let data = "";
request.on("data", function(chunk) {
data += chunk.toString();
});
request.on("end", function() {
console.log({ data });
response.write("Request logged");
response.end();
});
});
s.listen(port);
console.log("Browse to http://127.0.0.1:" + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment