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?
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?
Share Improve this question asked Mar 1, 2014 at 19:04 EogcloudEogcloud 1,3654 gold badges19 silver badges46 bronze badges 3- 1 Found this one stackoverflow./questions/6528876/…. Helpful? – loveNoHate Commented Mar 1, 2014 at 19:22
- 1 Found the answer in the 2nd ment, thank you! – Eogcloud Commented Mar 1, 2014 at 19:31
- @Eogcloud They both work, but I'd suggest using the method in the first method rather than the second. – loganfsmyth Commented Mar 2, 2014 at 7:51
1 Answer
Reset to default 10Found 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); });