How can you define multiple route paths for a single controller method in NestJS?
Explanation:
NestJS allows defining multiple route paths for a single method by providing an array of strings as the first argument to the route decorator (@Get()
, @Post()
, etc.).
What is the purpose of the useFactory
property in a FactoryProvider
?
Explanation:
The useFactory
property in a FactoryProvider
is used to define a factory function. This function is responsible for creating and returning an instance of the provider. It can be asynchronous and can inject dependencies.
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.
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 interface must a class implement to act as an Interceptor in NestJS?
Explanation:
Classes acting as Interceptors in NestJS must implement the NestInterceptor
interface, which provides the intercept
method for handling requests and responses.
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.
Which of the following is NOT a valid HTTP method for defining routes in NestJS?
Explanation:
NestJS uses standard HTTP methods for routing. RENDER
is not a standard HTTP method; it's often associated with server-side templating engines.
After installing the NestJS CLI, what command is used to initiate a new NestJS project?
Explanation:
The nest new
command followed by your desired project name is the standard way to start a new NestJS project using the CLI.
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.
How are controllers related to modules in NestJS?
Explanation:
Controllers are always defined within a specific module in NestJS. This association determines their scope and how they are managed within the application's structure.