Reputation:
I'm using NodeJS with Express and when an Endpoint is not found Express returns
I'd like to return a Custom 404 Message instead of the above image whenever an Endpoint is miss-typed.
I've tried adding the following to app.js
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
But this just returns ALL endpoints with
Sorry can't find that!
Upvotes: 2
Views: 1939
Reputation: 38519
You need to make that this the last 'route' in app.js
app.use(function (req, res, next) {
res.status(404).send("Sorry can't find that!")
})
The order your specify your routes is important.
Upvotes: 3