0
0
Expressframework~20 mins

Why understanding res matters in Express - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express Response Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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');
});
AThe client receives 'Hello World' with HTTP status 200.
BThe client receives an empty response with HTTP status 200.
CThe client receives 'Hello World' with HTTP status 404.
DThe client receives an error because res.status must be called after res.send.
Attempts:
2 left
💡 Hint
Think about the order of res.status and res.send and what they do.
state_output
intermediate
2: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);
});
A500 Internal Server Error
B201 Created
C200 OK
DNo response sent, request hangs
Attempts:
2 left
💡 Hint
Consider when the status code is set relative to sending the response.
🔧 Debug
advanced
2: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');
});
Ares.send must be called with a status code first.
BCannot send multiple responses for one request; second res.send causes error.
Cres.send requires a callback function to avoid errors.
Dres.send can only send JSON, sending string causes error.
Attempts:
2 left
💡 Hint
Think about how many times you can send a response per request.
🧠 Conceptual
advanced
2:00remaining
What role does 'res' play in Express middleware?
In Express middleware functions, what is the main purpose of the 'res' object?
ATo build and send the HTTP response back to the client.
BTo parse incoming request data from the client.
CTo manage server-side database connections.
DTo handle routing and URL matching.
Attempts:
2 left
💡 Hint
Think about what happens after the server processes a request.
📝 Syntax
expert
2: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?
Ares.send({ success: true }).status(201);
Bres.json({ success: true }).status(201);
Cres.sendStatus(201).json({ success: true });
Dres.status(201).json({ success: true });
Attempts:
2 left
💡 Hint
Remember method chaining order matters in Express response.