Errors in Express.js can be handled using the Express middleware “error-handler”. This middleware takes an error object as its first argument and a function as its second argument. The function will be called with the error object as its only argument.
For example:
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(500).send(‘Something broke!’);
});