How to Redirect 404 Errors to a Page in ExpressJS?

Discussion RoomCategory: CodingHow to Redirect 404 Errors to a Page in ExpressJS?
mohan asked 6 years ago

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”});
});

Scroll to Top