What is a key advantage of using a message broker like RabbitMQ or Kafka for NestJS microservice communication?
Automatic user interface generation
Improved error handling and retries
Reduced need for code testing
Simplified database management
Which of the following transport mechanisms is well-suited for building highly scalable and real-time NestJS microservices?
Redis
HTTP
File system
Email
When might you choose to use a custom decorator instead of middleware in NestJS?
When you want to modify the routing behavior of your application.
When you need to perform asynchronous operations before or after a request.
When you need access to the request or response objects within the logic.
When the logic you want to apply is highly specific to a single method or parameter.
What is the role of the catch() method in a custom HTTP exception filter?
catch()
It re-throws the exception to be handled by a global exception filter.
It logs the exception to the console.
It handles the exception and sends a customized error response.
It determines the appropriate HTTP status code for the exception.
What is the typical role of a @SetMetadata decorator when working with custom Guards in NestJS?
@SetMetadata
It defines the structure of the response sent back to the client.
It directly handles user authentication logic.
It is used to inject dependencies into Guards.
It attaches custom metadata to route handlers, which can be accessed within the Guard to make authorization decisions.
How can you apply a Pipe globally to all route handlers in a NestJS application?
By providing the Pipe in the 'providers' array of the AppModule.
By registering the Pipe in the 'pipes' array within the @Controller() decorator.
By using the 'useGlobalPipes()' method in the 'main.ts' file.
By using the @Global() decorator on the Pipe class.
In NestJS, what is the primary mechanism for implementing an event-driven architecture?
Leveraging a message queue system like RabbitMQ
Utilizing NestJS's built-in event emitter and listener system
Directly calling methods between classes
Using HTTP requests and responses
How do you define an event listener in a NestJS service?
By implementing the EventEmitter interface
EventEmitter
Using the @Listen() decorator on a service method
@Listen()
By injecting the EventEmitter and manually subscribing to events
Using the @OnApplicationBootstrap() lifecycle hook
@OnApplicationBootstrap()
How can you access the currently authenticated user's information within a NestJS controller after successful authentication?
By injecting the 'Request' object
By querying the database directly within the controller
By using the 'AuthService'
By accessing the 'user' property of the 'req' object within the controller method
Which interface does a logging interceptor primarily implement in NestJS to intercept incoming requests and outgoing responses for logging purposes?
LoggingInterceptor
OnResponseInterceptor
OnRequestInterceptor
NestInterceptor