Challenge - 5 Problems
Express Response Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Express route send to the client?
Consider this Express route handler. What will the client receive as the response body?
Express
app.get('/hello', (req, res) => { res.status(200); res.send('Hello World'); });
Attempts:
2 left
💡 Hint
Think about the order of res.status and res.send and what they do.
✗ Incorrect
res.status sets the HTTP status code. res.send sends the response body. Calling res.status before res.send sets the status correctly. So the client gets 'Hello World' with status 200.
❓ state_output
intermediate2:00remaining
What is the HTTP status code sent here?
Look at this Express handler. What status code will the client receive?
Express
app.get('/test', (req, res) => { res.send('Done'); res.status(201); });
Attempts:
2 left
💡 Hint
Consider when the status code is set relative to sending the response.
✗ Incorrect
res.send sends the response immediately with default status 200. Calling res.status after res.send has no effect.
🔧 Debug
advanced2:00remaining
Why does this Express code cause an error?
This code throws an error when a request is made. What is the cause?
Express
app.get('/error', (req, res) => { res.send('First response'); res.send('Second response'); });
Attempts:
2 left
💡 Hint
Think about how many times you can send a response per request.
✗ Incorrect
Express allows only one response per request. Calling res.send twice causes an error because the response is already finished.
🧠 Conceptual
advanced2:00remaining
What role does 'res' play in Express middleware?
In Express middleware functions, what is the main purpose of the 'res' object?
Attempts:
2 left
💡 Hint
Think about what happens after the server processes a request.
✗ Incorrect
'res' is the response object used to send data, status codes, and headers back to the client.
📝 Syntax
expert2:00remaining
Which option correctly sends JSON with status 201?
You want to send a JSON response with HTTP status 201. Which code snippet does this correctly?
Attempts:
2 left
💡 Hint
Remember method chaining order matters in Express response.
✗ Incorrect
res.status sets the status code and returns res, so chaining .json sends JSON with that status. Other options call methods in wrong order or use incompatible methods.