0
0
Expressframework~20 mins

res.status for status codes in Express - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Express Status Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does res.status(404).send('Not Found') do?

In an Express app, what is the effect of calling res.status(404).send('Not Found') inside a route handler?

Express
app.get('/item', (req, res) => {
  res.status(404).send('Not Found');
});
ASends a response with HTTP status 200 and body 'Not Found'.
BThrows an error and crashes the server.
CSends a response with HTTP status 404 but no body.
DSends a response with HTTP status 404 and body 'Not Found'.
Attempts:
2 left
💡 Hint

Think about what res.status() sets and what send() does.

📝 Syntax
intermediate
2:00remaining
Which option correctly sets status 201 and sends JSON data?

Choose the correct Express code to send a 201 status with JSON {"success": true}.

Ares.status(201).sendJson({success: true});
Bres.send(201).json({success: true});
Cres.status(201).json({success: true});
Dres.status = 201; res.json({success: true});
Attempts:
2 left
💡 Hint

Remember the correct method to set status and send JSON.

🔧 Debug
advanced
2:00remaining
Why does res.status(500).send() send a blank response?

In Express, what happens if you call res.status(500).send() without any argument?

Express
app.get('/error', (req, res) => {
  res.status(500).send();
});
AIt throws a TypeError because send() needs an argument.
BIt sends a 500 status with an empty body.
CIt sends a 500 status with the default error message.
DIt sends a 200 status with an empty body.
Attempts:
2 left
💡 Hint

Check what happens when send() is called with no argument.

state_output
advanced
2:00remaining
What is the status code after res.status(200).status(404).send('Oops')?

Consider this Express code snippet:

res.status(200).status(404).send('Oops');

What status code will the client receive?

A404
B200
C500
DIt causes an error and no response is sent.
Attempts:
2 left
💡 Hint

Think about method chaining and which status code is last set.

🧠 Conceptual
expert
2:00remaining
Which status code is most appropriate for a successful resource creation?

In REST APIs using Express, which HTTP status code should you set with res.status() when a new resource is successfully created?

A201
B200
C204
D400
Attempts:
2 left
💡 Hint

Think about the standard HTTP codes for resource creation.