This happens because even if you do not configure a middleware for error handling, express does it internally for you, so when an error occurs, all subsequent middlewares are skipped until the error handling middleware. How does express know what this middleware is? Because it has four arguments, error, req, res, next.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for the article, I learned something.
I have question, how does Express know that next(error), should be passed to the Error Handling middleware (which has 4 arguments)?
If there is a middleware that has (res, req, next) that was sat up before the Error Handling middleware, will it get first to handle the error?
Nasser
This happens because even if you do not configure a middleware for error handling, express does it internally for you, so when an error occurs, all subsequent middlewares are skipped until the error handling middleware. How does express know what this middleware is? Because it has four arguments, error, req, res, next.