Question

I'm sure information on this already exists, but I searched and don't know if my search terms are correct.

I have a node/express application and I want it so that when a user requests a route that doesn't exist, the server will return a specific page rather than the default "Cannot get X" page.

for example, if someone reqeusts

application/asdf 

but no route exists, I'd like to render the 404 page.

How does one do this?

Était-ce utile?

La solution

Found my answer! Thank you @dollarVar

2nd answer: How to redirect 404 errors to a page in ExpressJS?

I think you should first define all your routes and as the last route add

//The 404 Route (ALWAYS Keep this as the last route)
app.get('*', function(req, res){
  res.send('what???', 404);
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top