0
0
Expressframework~20 mins

res.send for general responses in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express res.send Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Express code send to the client?
Consider this Express route handler:
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!'); });
AA redirect to '/hello/world'
BThe string 'Hello World!' as the response body with status 200
CAn empty response with status 204
DA JSON object { message: 'Hello World!' }
Attempts:
2 left
💡 Hint
res.send sends the exact data you give it as the response body.
📝 Syntax
intermediate
2:00remaining
Which option correctly sends a JSON response using res.send?
You want to send this JSON object as a response:
{ success: true, data: [1, 2, 3] }

Which code correctly sends it using res.send?
Ares.send('success: true, data: [1, 2, 3]');
Bres.send(JSON.stringify({ success: true, data: [1, 2, 3] }));
Cres.send({ success: true, data: [1, 2, 3] });
Dres.send({ 'success': 'true', 'data': '[1, 2, 3]' });
Attempts:
2 left
💡 Hint
res.send can accept an object and automatically sends JSON.
🔧 Debug
advanced
2:00remaining
Why does this code cause an error?
Look at this Express handler:
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'); });
AError: Cannot set headers after they are sent to the client
BThe client receives '123Done' as a combined response
CThe client receives only 'Done' as the response
DThe server crashes with a syntax error
Attempts:
2 left
💡 Hint
You can only send one response per request.
state_output
advanced
2:00remaining
What is the Content-Type header when sending a number with res.send?
Given this code:
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); });
ANo Content-Type header is sent
Bapplication/json; charset=utf-8
Ctext/plain; charset=utf-8
Dtext/html; charset=utf-8
Attempts:
2 left
💡 Hint
Numbers are converted to strings when sent.
🧠 Conceptual
expert
2:00remaining
Which statement about res.send behavior is true?
Choose the correct statement about how res.send works in Express:
Ares.send ends the response process and cannot be called multiple times per request
Bres.send buffers the entire response before sending it to the client
Cres.send automatically sets Content-Type to application/json when sending objects
Dres.send can only send strings and buffers, not objects or numbers
Attempts:
2 left
💡 Hint
Think about what happens after res.send is called.