Recall & Review
beginner
What does the
res.status(code) method do in Node.js?It sets the HTTP status code of the response that the server sends back to the client. For example,
res.status(404) sets the status to 'Not Found'.Click to reveal answer
beginner
Name a common HTTP status code for a successful GET request.
The status code
200 means 'OK', which indicates the request was successful and the server is sending the requested data.Click to reveal answer
beginner
What is the purpose of
res.send() in Node.js?It sends the response body to the client and ends the response process. You can send strings, objects, or buffers with it.
Click to reveal answer
intermediate
How do you send a JSON response with a status code of 201 in Node.js?
Use
res.status(201).json(data). This sets the status to 'Created' and sends the JSON data to the client.Click to reveal answer
beginner
What status code indicates that the client made a bad request?
Status code
400 means 'Bad Request'. It tells the client that the server could not understand the request due to invalid syntax.Click to reveal answer
Which method sets the HTTP status code in a Node.js response?
✗ Incorrect
res.status() sets the HTTP status code before sending the response.What status code means 'Not Found'?
✗ Incorrect
Status code
404 means the requested resource was not found.How do you send a JSON response in Node.js?
✗ Incorrect
res.json() sends a JSON response to the client.Which status code indicates a successful resource creation?
✗ Incorrect
Status code
201 means 'Created', used when a resource is successfully created.What does
res.send() do?✗ Incorrect
res.send() sends the response body and ends the response process.Explain how to send a response with a custom status code and JSON data in Node.js.
Think about chaining methods to set status and send JSON.
You got /4 concepts.
List three common HTTP status codes and what they mean when used in a Node.js response.
Focus on success, client error, and resource not found.
You got /4 concepts.