Skip to content

Instantly share code, notes, and snippets.

@v-vashchenko
Last active May 22, 2019 11:56
Show Gist options
  • Save v-vashchenko/f80cc6939222dfa60d48d0f6b871b552 to your computer and use it in GitHub Desktop.
Save v-vashchenko/f80cc6939222dfa60d48d0f6b871b552 to your computer and use it in GitHub Desktop.
Node request logger
const logRequestStart = (req, res, next) => {
console.log('\x1b[33m%s\x1b[0m', `${req.method} ${req.originalUrl}`)
res.on('finish', () => {
console.log(`${res.statusCode} ${res.statusMessage}; ${res.get('Content-Length') || 0}b sent`)
})
next()
}
app.use(logRequestStart)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment