2

I'm using NodeJS with Express and when an Endpoint is not found Express returns enter image description here

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!

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.