Challenge - 5 Problems
Response Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the HTTP status code sent by this Express response?
Consider this Express.js code snippet. What status code will the client receive?
Node.js
app.get('/test', (req, res) => { res.status(201).send('Created'); });
Attempts:
2 left
💡 Hint
Look at the status method argument.
✗ Incorrect
The res.status(201) sets the HTTP status code to 201, which means 'Created'.
❓ component_behavior
intermediate2:00remaining
What will the response body be for this Express handler?
Given this Express route handler, what will the client see in the response body?
Node.js
app.get('/hello', (req, res) => { res.status(200).json({ message: 'Hello World' }); });
Attempts:
2 left
💡 Hint
Check the method used to send the response.
✗ Incorrect
res.json sends a JSON string of the object, so the client receives {"message":"Hello World"}.
📝 Syntax
advanced2:00remaining
Which option correctly sends a 404 status with a plain text message?
Choose the correct Express.js code to send a 404 status with 'Not Found' text.
Attempts:
2 left
💡 Hint
Check the correct usage of res.status and res.send methods.
✗ Incorrect
Option C correctly sets status 404 and sends plain text. Option C is deprecated syntax. Option C is invalid because sendStatus only takes status code. Option C sends JSON string, not plain text.
🔧 Debug
advanced2:00remaining
Why does this Express handler cause an error?
Identify the error in this Express route handler code.
Node.js
app.get('/error', (req, res) => { res.sendStatus(200).send('OK'); });
Attempts:
2 left
💡 Hint
Check what res.sendStatus returns and if chaining is allowed.
✗ Incorrect
res.sendStatus sends the status and ends the response. Calling send after it causes an error because response is already finished.
🧠 Conceptual
expert2:00remaining
Which status code best fits this scenario in an Express API?
You have an API endpoint that successfully processes a request but does not return any content. Which HTTP status code should you use?
Attempts:
2 left
💡 Hint
Think about status codes that indicate success but no response body.
✗ Incorrect
204 means success with no content returned. 200 usually includes content. 202 means accepted but processing not complete. 404 means resource not found.