Challenge - 5 Problems
Express 404 Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when a request hits this 404 handler?
Consider this Express 404 handler middleware. What will the client receive if they request a non-existent route?
Express
app.use((req, res) => {
res.status(404).send('Page not found');
});Attempts:
2 left
💡 Hint
Look at the status code set and the response sent.
✗ Incorrect
This middleware sets the HTTP status to 404 and sends the text 'Page not found'. So the client gets a 404 status with that message.
📝 Syntax
intermediate2:00remaining
Which 404 handler code snippet is syntactically correct?
Identify the valid Express 404 handler middleware from the options below.
Attempts:
2 left
💡 Hint
Check for balanced parentheses and braces.
✗ Incorrect
Option A has correct syntax with balanced braces and parentheses. Others have missing or misplaced characters causing syntax errors.
🔧 Debug
advanced2:00remaining
Why doesn't this 404 handler run for requests to '/hello'?
Given this Express app code, why does the 404 handler not get called when requesting '/hello'?
Express
app.get('/hello', (req, res) => { res.send('Hello world'); }); app.use((req, res) => { res.status(404).send('Not found'); }); app.use((err, req, res, next) => { res.status(500).send('Server error'); });
Attempts:
2 left
💡 Hint
Think about which routes match requests and middleware order.
✗ Incorrect
The route '/hello' matches requests to '/hello' and sends a response, so the request never reaches the 404 handler middleware.
❓ state_output
advanced2:00remaining
What is the response status and body for this 404 handler with next() call?
Analyze this Express 404 handler. What will the client receive?
Express
app.use((req, res, next) => {
res.status(404);
next();
});
app.use((req, res) => {
res.send('Page missing');
});Attempts:
2 left
💡 Hint
Check how status and next() affect response.
✗ Incorrect
The first middleware sets status 404 and calls next(), so the next middleware sends the body with status 404 preserved.
🧠 Conceptual
expert3:00remaining
Which statement about Express 404 handlers is true?
Select the correct statement about how Express handles 404 Not Found errors.
Attempts:
2 left
💡 Hint
Think about middleware order and parameters.
✗ Incorrect
404 handlers catch unmatched routes and must be last. Error handlers have four parameters; 404 handlers usually have three. Express does not auto-send 404 responses. 404 handlers can send any content type.