What is a key advantage of using a message broker like RabbitMQ or Kafka for NestJS microservice communication?
Simplified database management
Reduced need for code testing
Automatic user interface generation
Improved error handling and retries
What is the purpose of a Model in Mongoose?
To create and manage database migrations
To handle user authentication and authorization
To define a database connection string
To interact with a specific collection in the database based on a defined schema
What is the role of the catch() method in a custom HTTP exception filter?
catch()
It handles the exception and sends a customized error response.
It logs the exception to the console.
It re-throws the exception to be handled by a global exception filter.
It determines the appropriate HTTP status code for the exception.
What is the primary function of a Pipe in NestJS?
To transform input data into the desired format.
To define middleware for routing HTTP requests.
To manage dependency injection within the application.
To handle database queries and operations.
Which of these is NOT a common method for storing session data in a NestJS application?
Local variable storage
In-memory storage
File system storage
Database storage
In NestJS, what is the primary mechanism for implementing an event-driven architecture?
Directly calling methods between classes
Using HTTP requests and responses
Leveraging a message queue system like RabbitMQ
Utilizing NestJS's built-in event emitter and listener system
What is the main function of a transformation interceptor in NestJS?
To modify the incoming request or outgoing response data
To validate the structure and data types of incoming requests
To log request and response details for debugging purposes
To handle errors and exceptions thrown during request processing
When would you create a custom Guard in NestJS instead of relying on built-in solutions?
When you need to send emails after a user signs up.
When you need to perform standard JWT (JSON Web Token) authentication.
When you want to handle database migrations automatically.
When you need to implement authorization logic tailored to your application's specific requirements, which might involve checking for custom permissions or conditions.
How do you register a global exception filter in NestJS?
By adding the global filter class to the providers array in the module definition.
providers
By extending the base ExceptionFilter class and annotating it with the @Global() decorator.
ExceptionFilter
@Global()
By using the useGlobalFilters() method in the main.ts file.
useGlobalFilters()
main.ts
By using the @Catch() decorator on the global filter class.
@Catch()
What decorator is used to register a caching interceptor globally in a NestJS application?
@GlobalCache()
@UseInterceptors(CacheInterceptor)
@Cache()
@GlobalInterceptor(CacheInterceptor)