In Express, an error handler is a middleware with four parameters (err, req, res, next) declared after the routes. It receives all errors passed by next(err) and produces a consistent response. It logs the details internally without exposing them to the client.
Example
app.use((err, req, res, next) => {
res.status(err.status ?? 500).json({ message: 'Internal error' });
});