Created
October 31, 2019 14:04
-
-
Save omar2205/671d3dbc89418510681f6a964bffb153 to your computer and use it in GitHub Desktop.
express logger
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 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