Express 5 · Error handling

Add an error handler

Define it last. It takes four arguments.

app.use((err, req, res, next) => {
  console.error(err);
  res.status(500).json({ error: "Internal Server Error" });
});

Official Express 5 documentation

More error handling commands

All error handling commands · Express 5 cheatsheet

Was this page helpful?