New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
My async route throws when a database call fails, and the whole server crashes instead of sending back an error response.
What you'll have at the end
One error-handling middleware that turns any async route's rejection into a matching HTTP status code, with every promise in the app either returned to it or given its own catch so none of them can crash the process.
You need
An Express app already listening for requests, with at least one route that calls an async database or API function and no error-handling middleware defined yet.
Not covered
Wiring a process-wide crash-and-restart safety net for a background job or worker with no request waiting on it, which is a different problem once nobody is left to answer.
Checked 25 Aug 2026
Part of the Express.js cookbook