Why Async Errors Silently Crash Express 4 Apps and How Fastify Handles Them
In Express 4, async route handlers return a Promise before it settles, meaning the framework's synchronous try/catch block cannot intercept a later rejection. When that Promise rejects, Node.js emits an unhandledRejection event instead of routing the error to Express middleware, and since Node 15 this can crash the entire process by default. The standard fix in Express 4 is an asyncHandler wrapper that explicitly chains .catch(next), forwarding rejections into the error middleware chain. Express 5, released as a stable major version in 2024, resolves this at the framework level by automatically forwarding rejected Promises into the error chain without any wrapper. Fastify avoids the problem altogether by natively awaiting each handler in its pipeline, catching rejections and routing them through its setErrorHandler for consistent JSON error responses.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in