Last active
May 14, 2017 13:10
-
-
Save mrister/bd8aca33999af081e9b21552e75d35b3 to your computer and use it in GitHub Desktop.
Example morgan express app with combined 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 morgan = require('morgan'); | |
const app = express(); | |
// use combined preset, see https://github.com/expressjs/morgan#combined | |
app.use(morgan('combined')); | |
app.get('/', (req, res) => { | |
res.send('Hello from Express.js server!') | |
}); | |
const PORT = 3000; | |
// run the server | |
app.listen(PORT, () => { | |
console.log(`Example app listening on port ${PORT}!`); | |
}); | |
/* | |
* Opening the browser at http://localhost:3000 prints: | |
* Hello from Express.js server! | |
* And in the console output you can see morgan logging a message like the below one for each request: | |
* | |
* ::1 - - [14/May/2017:12:29:09 +0000] "GET / HTTP/1.1" 200 29 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment