0
0
Expressframework~20 mins

Status code conventions in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Status Code Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding HTTP status codes in Express
Which HTTP status code should you use in Express when a client sends a request with missing required data?
A404 Not Found
B200 OK
C400 Bad Request
D500 Internal Server Error
Attempts:
2 left
💡 Hint
Think about what status code means the client made a bad request.
component_behavior
intermediate
2:00remaining
Express response status for successful resource creation
What status code does Express typically send when a new resource is successfully created?
A201 Created
B202 Accepted
C204 No Content
D200 OK
Attempts:
2 left
💡 Hint
This code means the server created something new.
📝 Syntax
advanced
2:00remaining
Correct usage of status codes in Express response
Which Express code snippet correctly sends a 404 status with a JSON error message?
Ares.json(404, { error: 'Not found' });
Bres.status(404).json({ error: 'Not found' });
Cres.status(404).send({ error: 'Not found' });
Dres.sendStatus(404).json({ error: 'Not found' });
Attempts:
2 left
💡 Hint
Check the chaining and method usage for setting status and sending JSON.
state_output
advanced
2:00remaining
Output status code for unauthorized access in Express
What status code will Express send if you use res.status(401).send('Unauthorized')?
Express
app.get('/secret', (req, res) => {
  res.status(401).send('Unauthorized');
});
A401 Unauthorized with body 'Unauthorized'
B200 OK with body 'Unauthorized'
C403 Forbidden with body 'Unauthorized'
D500 Internal Server Error
Attempts:
2 left
💡 Hint
The status code you set is sent as the HTTP response status.
🔧 Debug
expert
2:00remaining
Identify the error in status code usage
What error occurs when running this Express code snippet?
app.get('/data', (req, res) => {
  res.status(201).send('Created');
  res.status(200).send('OK');
});
Express
app.get('/data', (req, res) => {
  res.status(201).send('Created');
  res.status(200).send('OK');
});
ANo error, sends 201 Created
BSyntaxError: Unexpected token
CNo error, sends 200 OK
DError: Cannot set headers after they are sent to the client
Attempts:
2 left
💡 Hint
Think about sending multiple responses in one request.