Log requests to nodejs express

Viewed 9200

I want to log all requests like this:

8:04:20 PM - info: /api/v2 200 8:04:22 PM - info: /api/v2/asdf 200

However, in express, the middleware is called before the request is processed, so I cannot get the real response code. I always get 200. What is the right approach to accomplish this?

3 Answers

Here you go:

app.use((req, res, next)=> {
  console.log('I run on every request!');
  next();
})
Related