What is the role of the 'main.ts' file in a NestJS project?
Explanation:
The main.ts
file is the entry point of your NestJS application. It bootstraps the NestJS application, often setting up the listening port and other core configurations.
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.
Which HTTP method does the @Post()
decorator handle?
Explanation:
The @Post()
decorator is used to designate a controller method as a handler for incoming HTTP POST requests, typically used for creating resources.
Which design pattern heavily influences the architecture of NestJS?
Explanation:
Dependency Injection is a core principle in NestJS. It allows for loosely coupled modules and promotes better testability and flexibility within your application.
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.
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 decorator is used for handling HTTP requests meant for updating resources?
Explanation:
The @Put()
decorator marks a controller method for handling HTTP PUT requests, typically used for complete updates of existing resources.
What is the role of CallHandler
in the intercept
method of an Interceptor?
Explanation:
The CallHandler
in the intercept
method allows you to call the next Interceptor in line or, if it's the last Interceptor, to trigger the execution of the route handler.
What is the purpose of the return
statement in a NestJS controller method?
Explanation:
The value returned from a NestJS controller method forms the response sent back to the client. This can be a simple object, a string, or more complex data.
What is the default scope of a provider in NestJS?
Explanation:
In NestJS, providers are singletons by default. This means that a single instance of the provider is created and shared across the entire application.