What is the command to install the NestJS CLI globally?
npm install nestjs
npm install -g @nestjs/cli
install -g nestjs
yarn global add nestjs
What is the primary function of middleware in NestJS?
To render dynamic views on the server.
To define API routes.
To handle database operations.
To intercept and modify incoming requests and outgoing responses.
When using @Inject(), what should you provide as the argument?
@Inject()
The string 'inject'.
The class name of the dependency.
The injection token of the dependency.
An instance of the dependency.
How do you access query parameters in a NestJS controller method?
Using @Body()
@Body()
Using @Query()
@Query()
Using @Headers()
@Headers()
Using @Param()
@Param()
What is NOT a benefit of using Dependency Injection in NestJS?
Enhanced code reusability.
Improved code testability.
Better maintainability of code.
Increased code coupling.
Which decorator is used to define an Interceptor class in NestJS?
@Injectable()
@Module()
@Controller()
@Interceptor()
Which decorator allows you to access route parameters in NestJS?
@Req()
What is the difference between a provider and a service in NestJS?
Providers are decorated with @Injectable(), while services are decorated with @Service().
Providers are classes that can be injected as dependencies, while a service is a specific type of provider with business logic.
Providers are used for database operations, while services handle business logic.
Providers and services are essentially the same thing, with no real distinction.
Which of the following is NOT a valid HTTP method for defining routes in NestJS?
DELETE
PATCH
RENDER
PUT
How can you access the currently logged-in user within your middleware in NestJS?
By using the user property of the Response object.
user
Response
By querying the database directly within the middleware.
By accessing the req.user object, assuming you have an authentication middleware set up.
req.user
By injecting the Request object into the middleware function.
Request