0
0
Node.jsframework~20 mins

Response methods and status codes in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Response Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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');
});
A404
B201
C200
D500
Attempts:
2 left
💡 Hint
Look at the status method argument.
component_behavior
intermediate
2: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' });
});
Aundefined
BHello World
C{"msg":"Hello World"}
D{"message":"Hello World"}
Attempts:
2 left
💡 Hint
Check the method used to send the response.
📝 Syntax
advanced
2: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.
Ares.send(404, 'Not Found');
Bres.sendStatus(404, 'Not Found');
Cres.status(404).send('Not Found');
Dres.status(404).json('Not Found');
Attempts:
2 left
💡 Hint
Check the correct usage of res.status and res.send methods.
🔧 Debug
advanced
2: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');
});
Ares.sendStatus ends the response; calling send after causes an error.
BsendStatus requires two arguments; missing second argument causes error.
Cres.sendStatus is not a function; typo in method name.
Dsend method cannot be chained after status method.
Attempts:
2 left
💡 Hint
Check what res.sendStatus returns and if chaining is allowed.
🧠 Conceptual
expert
2: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?
A204 No Content
B200 OK
C202 Accepted
D404 Not Found
Attempts:
2 left
💡 Hint
Think about status codes that indicate success but no response body.