0
0
Expressframework~5 mins

res.status for status codes in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does res.status() do in Express?

res.status() sets the HTTP status code for the response sent to the client. It tells the browser or client if the request was successful, failed, or something else.

Click to reveal answer
beginner
How do you send a 404 status code with a message using res.status()?

You chain res.status(404) with .send() like this: res.status(404).send('Not Found'). This sets the status and sends the message.

Click to reveal answer
beginner
Why is it important to set the correct status code in Express responses?

Correct status codes help the client understand what happened. For example, 200 means success, 404 means not found, and 500 means server error. This helps browsers and APIs handle responses properly.

Click to reveal answer
intermediate
Can you chain res.status() with other response methods? Give an example.

Yes, you can chain it with methods like .json(), .send(), or .end(). Example: res.status(201).json({ message: 'Created' }) sends a 201 status with JSON data.

Click to reveal answer
beginner
What is the default status code if you don't use res.status() in Express?

The default status code is 200, which means the request was successful.

Click to reveal answer
What does res.status(500) indicate?
ARequest was successful
BResource not found
CServer error occurred
DClient sent bad request
How do you send a 201 status code with JSON data in Express?
Ares.status(jsonData).send(201)
Bres.send(201, jsonData)
Cres.json(201, jsonData)
Dres.status(201).json(jsonData)
If you forget to use res.status(), what status code is sent by default?
A200
B500
C404
D302
Which method can you chain after res.status() to send a plain text response?
Ares.json()
Bres.send()
Cres.end()
Dres.write()
What status code should you use to indicate a resource was not found?
A404
B200
C500
D301
Explain how to use res.status() to send a 403 Forbidden response with a message.
Think about chaining methods to set status and send text.
You got /3 concepts.
    Describe why setting the correct HTTP status code in Express responses is important for clients.
    Imagine how a browser or app knows what happened after a request.
    You got /3 concepts.