Skip to content

Instantly share code, notes, and snippets.

@manniru
Created December 26, 2022 10:13
Show Gist options
  • Save manniru/b2ba94d6edee09646ef2b3dca42aea3a to your computer and use it in GitHub Desktop.
Save manniru/b2ba94d6edee09646ef2b3dca42aea3a to your computer and use it in GitHub Desktop.
write simple nodejs server that display all requests data in console
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