Home > front end >  Why does order matter in a middleware file?
Why does order matter in a middleware file?

Time:11-24

I have an express app that I just added an APM to monitor my app. It wasn't reporting to the APM until I was suggested to require their import at the top of my middleware file. Why does order matter in a middleware file?

CodePudding user response:

Order matters in middleware because middleware functions are executed in a sequence and you'd need to execute one before the other in order to utilize its functionality.

For example, let's say you have two middleware functions, the first modifies the req object by adding the current user's credentials and the second ends the request-response cycle.
Invoking the second function will terminate the cycle before modifying the req object.

  • Related