How to Redirect 404 Errors to A Page In ExpressJS?

In server.js add the subsequent code to send 404 errors back to a page in our ExpressJS App:

/* Define fallback route */
app.use(function(req, res, next) {
res.status(404).json({errorCode: 404, errorMsg: “route not found”});
});

Leave a Reply