Home >> Tutorials >> Node.js Express Middleware: Error Handling

Express.js middleware in Node.js

Q:- How to handle exception globally using Express.js middleware in Node.js?

In Express.js use - middleware to handle common errors in api/web requests.

// Handle errors
app.use((err, req, res, next) => {
    if (! err) {
        return next();
    }

    res.status(500);
    res.send('500: Internal server error');
});
Full Stack Tutorials

Author @FullStackTutorials | View all Articles