Recall & Review
beginner
What is a 404 Not Found handler in Express?
It is a middleware function that catches requests to routes that do not exist and sends a 404 status with a message to the client.
Click to reveal answer
beginner
Where should you place the 404 Not Found handler in your Express app?
It should be placed after all other route handlers so it only runs if no route matches the request.
Click to reveal answer
beginner
How do you send a 404 status code in Express?
Use res.status(404).send('Not Found') or res.status(404).json({ message: 'Not Found' }) inside the handler.
Click to reveal answer
beginner
Example code snippet for a simple 404 Not Found handler in Express?
app.use((req, res) => { res.status(404).send('404 Not Found'); });
Click to reveal answer
beginner
Why is it important to have a 404 Not Found handler in your Express app?
It improves user experience by clearly telling users when a page or resource does not exist, instead of leaving them with a blank or confusing error.
Click to reveal answer
Where should the 404 Not Found handler be placed in an Express app?
✗ Incorrect
The 404 handler runs only if no other route matches, so it must be last.
What status code does a 404 Not Found handler send?
✗ Incorrect
404 means the requested resource was not found.
Which Express method sets the HTTP status code in the response?
✗ Incorrect
res.status() sets the status code before sending the response.
What happens if you do not add a 404 handler in Express?
✗ Incorrect
Without a 404 handler, requests to unknown routes may hang or get a default empty response.
How do you define a 404 handler middleware in Express?
✗ Incorrect
A 404 handler uses app.use with a function that handles unmatched requests.
Explain how to create and use a 404 Not Found handler in an Express app.
Think about middleware order and response status
You got /4 concepts.
Why is a 404 Not Found handler important for user experience in web apps?
Consider what happens if users get no feedback
You got /4 concepts.