kumail
kumail

Reputation: 1409

Access get request in express with middleware

Is there any way to access the request object that is sent to any route without accessing it in a .get or something like that but instead access any request sent to express globally?

Upvotes: 0

Views: 642

Answers (1)

Quentin
Quentin

Reputation: 943556

Yes. That's the most of the point of middleware.

Quoting from the documentation:

var requestTime = function (req, res, next) {
  req.requestTime = Date.now()
  next()
}

app.use(requestTime)

Upvotes: 2

Related Questions