0
0
Node.jsframework~5 mins

Response methods and status codes in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Ares.json()
Bres.status()
Cres.send()
Dres.write()
What status code means 'Not Found'?
A404
B200
C500
D301
How do you send a JSON response in Node.js?
Ares.json()
Bres.writeJson()
Cres.send()
Dres.sendJson()
Which status code indicates a successful resource creation?
A500
B400
C403
D201
What does res.send() do?
AOnly sends JSON data
BSets the status code
CSends the response body and ends the response
DOnly sends headers
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.