Skip to content

Instantly share code, notes, and snippets.

@omar2205
Created October 31, 2019 14:04
Show Gist options
  • Save omar2205/671d3dbc89418510681f6a964bffb153 to your computer and use it in GitHub Desktop.
Save omar2205/671d3dbc89418510681f6a964bffb153 to your computer and use it in GitHub Desktop.
express logger
const express = require('express')
const app = express()
const log = console.log
const myLogger = (req, res, next) => {
res.on('finish', function() {
log(`${this.statusCode} ${req.method} ${req.path} - ${req.headers['cf-connecting-ip']} `)
}
}
app.get('/', (req, res) => res.end('hello world!'))
app.use((req, res, next) => res.status(404).send('Not found.... :('))
app.listen(process.env.PORT, () => log('Online'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment