Challenge - 5 Problems
Express res.send Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Express code send to the client?
Consider this Express route handler:
What will the client receive when requesting
app.get('/hello', (req, res) => { res.send('Hello World!'); });What will the client receive when requesting
/hello?Express
app.get('/hello', (req, res) => { res.send('Hello World!'); });
Attempts:
2 left
💡 Hint
res.send sends the exact data you give it as the response body.
✗ Incorrect
The res.send method sends the string 'Hello World!' as the response body with HTTP status 200 by default.
📝 Syntax
intermediate2:00remaining
Which option correctly sends a JSON response using res.send?
You want to send this JSON object as a response:
Which code correctly sends it using
{ success: true, data: [1, 2, 3] }Which code correctly sends it using
res.send?Attempts:
2 left
💡 Hint
res.send can accept an object and automatically sends JSON.
✗ Incorrect
Passing an object to res.send automatically converts it to JSON and sets the Content-Type header.
🔧 Debug
advanced2:00remaining
Why does this code cause an error?
Look at this Express handler:
What error or behavior will happen when a client requests
app.get('/test', (req, res) => { res.send(123); res.send('Done'); });What error or behavior will happen when a client requests
/test?Express
app.get('/test', (req, res) => { res.send(123); res.send('Done'); });
Attempts:
2 left
💡 Hint
You can only send one response per request.
✗ Incorrect
Calling res.send twice causes an error because headers and body can only be sent once per request.
❓ state_output
advanced2:00remaining
What is the Content-Type header when sending a number with res.send?
Given this code:
What Content-Type header will the client receive?
app.get('/number', (req, res) => { res.send(42); });What Content-Type header will the client receive?
Express
app.get('/number', (req, res) => { res.send(42); });
Attempts:
2 left
💡 Hint
Numbers are converted to strings when sent.
✗ Incorrect
Sending a number with res.send converts it to a string and sets Content-Type to text/html; charset=utf-8.
🧠 Conceptual
expert2:00remaining
Which statement about res.send behavior is true?
Choose the correct statement about how
res.send works in Express:Attempts:
2 left
💡 Hint
Think about what happens after res.send is called.
✗ Incorrect
res.send ends the response and calling it again causes an error; it can send strings, buffers, numbers, and objects (converted to JSON).