0
0
Expressframework~5 mins

404 Not Found handler in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIt does not matter
BBefore all route handlers
CIn the middle of route handlers
DAfter all other route handlers
What status code does a 404 Not Found handler send?
A404
B200
C500
D302
Which Express method sets the HTTP status code in the response?
Ares.status()
Bres.setStatus()
Cres.sendStatus()
Dres.code()
What happens if you do not add a 404 handler in Express?
AExpress automatically sends a 404 response
BThe server crashes
CThe request hangs or returns a default response
DThe request is redirected
How do you define a 404 handler middleware in Express?
Aapp.get('/404', ...)
Bapp.use((req, res) => { ... })
Capp.post('/404', ...)
Dapp.route('/404')
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.