Search:   Dictionary All Posts
Store Your Knowledge at the Brain Bank!

Express Logging - Morgan & Winston

By Jamie in Lessons / Programming - JS  2.17.19  (Source)
Summary - A logger middleware for node/express will save data about every api request and log it so that developers can see exactly what happened with the request.
Morgan is one of the main logger middleware services used in Node and Express servers.

simply add it to the app.use()

app.use(morgan('combined'))

use morgan and pass in the type of logging you want it to do. see the source documentation for each option.

winston will replace console.log() in your api, so instead of console.log() you will use winston.log() and it will provide you with more detailed data about the request.

see the documentation for details