Recall & Review
beginner
What is the purpose of response handling in NestJS?
Response handling in NestJS manages how the server sends data back to the client after processing a request. It ensures the client receives the right data, status codes, and headers.
Click to reveal answer
beginner
How do you send a JSON response in a NestJS controller?
You return a JavaScript object or array from the controller method. NestJS automatically converts it to JSON and sends it with a 200 status code.
Click to reveal answer
intermediate
What decorator can you use to set a custom HTTP status code in NestJS?
You use the @HttpCode() decorator above a controller method to set a custom HTTP status code for the response.
Click to reveal answer
intermediate
How can you send a file as a response in NestJS?
You can inject the Response object from Express using @Res() and use its methods like res.sendFile() to send files directly.
Click to reveal answer
advanced
What is the difference between returning data and using @Res() in NestJS controllers?
Returning data lets NestJS handle the response automatically (recommended). Using @Res() gives you full control but disables automatic response handling, so you must manage headers and status codes yourself.
Click to reveal answer
In NestJS, what happens if you return an object from a controller method?
✗ Incorrect
Returning an object from a controller method automatically sends it as JSON with HTTP status 200.
Which decorator sets a custom HTTP status code for a response in NestJS?
✗ Incorrect
The @HttpCode() decorator sets a custom HTTP status code for the response.
What must you do if you use @Res() in a NestJS controller method?
✗ Incorrect
Using @Res() disables automatic response handling, so you must manually send the response.
How do you send a file in a NestJS controller?
✗ Incorrect
Inject the response object with @Res() and use res.sendFile() to send files.
What is the recommended way to handle responses in NestJS?
✗ Incorrect
Returning data lets NestJS handle serialization and status codes automatically, which is simpler and less error-prone.
Explain how NestJS handles response data when you return an object from a controller method.
Think about what NestJS does behind the scenes with returned data.
You got /3 concepts.
Describe the differences and trade-offs between returning data and using the @Res() decorator in NestJS controllers.
Consider ease of use versus control.
You got /3 concepts.