Web Framework Internals interview question · Most asked

How does Express handle a request, and how are errors routed?

Summary

Middleware and route handlers run in registration order; each responds or calls next(). next(err) or a synchronous throw skips to error-handling middleware (functions with four parameters). Unmatched requests get a 404. Express 4 ignores rejected promises from async handlers; Express 5 forwards them to error handlers.

Longer Answer

Register error handlers last, with four parameters, and never send a response twice.

Key Points

  • Registration order; next() continues.
  • Four-parameter error handlers.
  • Express 5 handles async rejections.
  • 404 when nothing responds.

Deep dive: Request Lifecycle: Express: The Middleware Stack and Error Handling

Explanation

What interviewers look for

Arity rule and async error behaviour.

More most-asked Web Framework Internals questions

← All Web Framework Internals questions