Created
January 28, 2020 19:25
-
-
Save mguida22/3a6a9cd9a401ff007660b35a618c66f9 to your computer and use it in GitHub Desktop.
Express Logging Middleware - https://mguida.com/blog/writing-express-middleware/
This file contains 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 port = 3000 | |
const logger = (req, res, next) => { | |
const timestamp = new Date() | |
console.log(`${timestamp} A request was made to: ${req.path}`) | |
next() | |
} | |
app.use(logger) | |
app.get('/hello', (req, res) => { | |
res.status(200).send('Hello World.') | |
}) | |
app.listen(port, () => { | |
console.log(`express server listening on port ${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment