1.

How To Redirect 404 Errors To A Page In Expressjs?

Answer»

In server.js add the following code to redirect 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"});
});

In server.js add the following code to redirect 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"});
});



Discussion

No Comment Found