Express 5 · Error handling

Handle errors in async routes

In Express 5, a rejected promise or thrown error in an async handler is passed to the error handler automatically.

app.get("/users/:id", async (req, res) => {
  const user = await db.findUser(req.params.id);
  res.json(user);
});

Official Express 5 documentation

More error handling commands

All error handling commands · Express 5 cheatsheet

Was this page helpful?