-
Create a Hello World!
express
app or use an existingexpress
project. -
Add support for
404
error handling. Add this custom middleware function after all other middleware that sends arequest
:app.use(function(request, response) { response.status(404); response.send('404: File Not Found'); });
- It's important this is the last middleware in your file just before the server is started. This function always returns a
404
response when it's invoked. In other words, if therequest
hasn't been sent by the time it reaches this function, it's a404
by process of elimination.
- It's important this is the last middleware in your file just before the server is started. This function always returns a
Last active
March 10, 2021 09:01
-
-
Save acidtone/f5a08d0f15e70c4ddf1d40571b9e0645 to your computer and use it in GitHub Desktop.
Express: Catch `404` errors
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment