Created
June 6, 2019 17:04
-
-
Save guimello/e661e2824f6225891eabdfa8760f989d to your computer and use it in GitHub Desktop.
Simple request logger server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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