Which decorator is used to define a custom exception filter in NestJS?
Explanation:
The @Catch()
decorator is specifically designed to mark a class as an exception filter, allowing it to handle specific exception types.
Which decorator is used to apply middleware to a specific route in NestJS?
Explanation:
The @UseMiddleware()
decorator is used to bind middleware to specific routes or controllers. You can apply it at the method level for individual routes or at the controller level to affect all routes within that controller.
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.
What is the purpose of the imports
array in a NestJS module definition?
Explanation:
The imports
array is used to establish dependencies between modules in NestJS. When you import a module, its exported components become available for use within the importing module.
What is the purpose of dependency injection in NestJS?
Explanation:
Dependency injection is a design pattern where dependencies are 'injected' into a class rather than being directly instantiated within the class. This promotes modularity, testability, and reusability.
What is the primary programming language used for developing NestJS applications?
Explanation:
NestJS is built on top of Node.js, which uses JavaScript as its primary programming language. While TypeScript is often preferred, you can write NestJS applications directly in JavaScript.
Which decorator allows you to access route parameters in NestJS?
Explanation:
The @Param()
decorator is used to inject route parameters into controller methods. It allows you to access values from the URL path defined in your route.
What is the purpose of the 'getStatus()' method in a custom exception filter?
Explanation:
The getStatus()
method allows the filter to access the appropriate HTTP status code from the caught exception, enabling it to set the correct status code for the error response.
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.
When using an Interceptor to modify the response, what is the best way to ensure type safety?
Explanation:
For type safety, define generics with the NestInterceptor
interface, specifying the expected request and response types, allowing TypeScript to perform type checking.