Created
December 26, 2022 10:13
-
-
Save manniru/b2ba94d6edee09646ef2b3dca42aea3a to your computer and use it in GitHub Desktop.
write simple nodejs server that display all requests data in console
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 server = http.createServer((req, res) => { | |
console.log(`Method: ${req.method}`) | |
console.log(`URL: ${req.url}`) | |
console.log(`Headers: ${JSON.stringify(req.headers)}`) | |
req.on('data', chunk => { | |
console.log(`Body: ${chunk}`) | |
}) | |
res.end() | |
}) | |
const port = 3000 | |
server.listen(port, () => { | |
console.log(`Server listening on port ${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment