What is a potential drawback of using singleton providers excessively in a large application?
Explanation:
While singletons offer benefits like shared state and reduced instantiation overhead, overusing them can lead to increased memory usage (as instances persist), slower startup (due to potential initialization chains), and challenges in isolating components during testing.
Inside an Interceptor's intercept
method, what object allows you to modify the response?
Explanation:
While you don't directly modify the response object, next.handle()
returns an Observable
representing the response stream, allowing you to apply RxJS operators for transformation.
What is the advantage of using built-in HTTP exception filters in NestJS?
Explanation:
NestJS's built-in filters simplify error handling by providing ready-to-use responses for standard HTTP errors, reducing the need for repetitive code.
What is the purpose of the @Body()
decorator?
Explanation:
The @Body()
decorator is used to access the entire request body sent by the client. It allows you to retrieve data sent in formats like JSON or form data.
How can you access the currently logged-in user within your middleware in NestJS?
Explanation:
If you're using an authentication middleware in NestJS, it typically attaches the authenticated user object to the request object. You can access this user information within your middleware by referring to req.user
.
What is the recommended way to access query parameters in a NestJS controller?
Explanation:
The @Query()
decorator provides a clean and type-safe way to access query parameters from the request object. It allows retrieving specific parameters or the entire query object.
Can a Controller access a Service's methods in NestJS?
Explanation:
In NestJS, a Controller can access a Service's methods by injecting an instance of the Service through the Controller's constructor. This is facilitated by NestJS's Dependency Injection mechanism.
How can you create a custom provider in NestJS that provides a value instead of a class?
Explanation:
The @ValueProvider()
decorator allows you to create a custom provider that provides a simple value. This is useful for injecting configuration values or other constant data.
How do you define middleware in NestJS?
Explanation:
Middleware in NestJS is defined as a function that takes three arguments: the request object, the response object, and a next function. This function signature is essential for NestJS to recognize and execute the middleware correctly.
What is the purpose of the @Get()
decorator in NestJS?
Explanation:
The @Get()
decorator is used to mark a controller method as a handler for incoming HTTP GET requests. It specifies that the method should be invoked when a GET request is made to the associated route.