How can you apply a transformation interceptor to a specific method in a controller in NestJS?
By registering the interceptor globally in the app.module.ts file
app.module.ts
By using the @Transform() decorator above the controller class
@Transform()
By extending the BaseController class and applying the interceptor in the constructor
BaseController
By using the @UseInterceptors() decorator at the method level
@UseInterceptors()
What is the primary function of a Pipe in NestJS?
To handle database queries and operations.
To define middleware for routing HTTP requests.
To transform input data into the desired format.
To manage dependency injection within the application.
What is the primary purpose of using Passport.js in a NestJS application?
Creating RESTful API endpoints
Managing database connections
Handling file uploads
Simplifying authentication and authorization logic
Which NestJS module is essential for creating TCP-based microservices?
@nestjs/core
@nestjs/common
@nestjs/microservices
@nestjs/platform-express
In a NestJS microservice architecture, how do services typically communicate with each other asynchronously?
Message queues
Shared memory
Direct method calls
Database triggers
How does the CQRS pattern improve the design of event-driven systems?
By eliminating the need for event listeners
By simplifying the handling of complex events
By separating read and write operations for better performance and scalability
By enforcing synchronous communication between components
What is the primary purpose of custom decorators in NestJS?
To directly modify the underlying Express.js request and response objects.
To define custom middleware functions within a controller.
To enhance code reusability and readability by encapsulating common logic.
To enforce strict type checking at compile time.
Can you have both global and custom HTTP exception filters in a NestJS application?
No, global exception filters take precedence and override any custom filters.
Yes, but custom filters will only handle exceptions not caught by global filters.
No, NestJS only allows you to define either global or custom exception filters, not both.
Yes, but you need to explicitly specify the order in which they should be executed.
In a NestJS application using CQRS, what is the role of a command handler?
To retrieve data from the database based on a query
To handle errors and exceptions within event listeners
To emit events in response to user actions
To process incoming events and update the application state
What object in the intercept() method of a transformation interceptor allows you to modify the response stream?
intercept()
context.getRequest()
context.getNext()
context.switchToHttp().getResponse()
context.switchToWs().getClient()