How does NestJS facilitate database integration?
NestJS provides a modular structure and decorators to integrate various database solutions
NestJS automatically configures database connections without any additional code
NestJS only supports relational databases and not NoSQL databases
NestJS prevents the use of external libraries like TypeORM or Mongoose
Which interface does a logging interceptor primarily implement in NestJS to intercept incoming requests and outgoing responses for logging purposes?
NestInterceptor
LoggingInterceptor
OnResponseInterceptor
OnRequestInterceptor
What is the primary advantage of using Mongoose with NestJS for database integration?
Mongoose automatically generates frontend UI components
Mongoose enables direct execution of SQL queries on MongoDB
Mongoose is used for managing relational databases in NestJS
Mongoose provides a schema-based solution for modeling data in MongoDB
What is the role of the catch() method in a custom HTTP exception filter?
catch()
It determines the appropriate HTTP status code for the exception.
It handles the exception and sends a customized error response.
It re-throws the exception to be handled by a global exception filter.
It logs the exception to the console.
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 process incoming events and update the application state
To emit events in response to user actions
What is the difference between HttpException and a custom exception class in NestJS?
HttpException
HttpException is used for generic HTTP errors, while custom exceptions represent specific business logic errors.
There is no practical difference; both can be used interchangeably for error handling.
HttpException is deprecated and should always be replaced with custom exception classes.
HttpException must be caught by custom exception filters, while custom exceptions are handled automatically.
How do you define an event listener in a NestJS service?
Using the @Listen() decorator on a service method
@Listen()
By injecting the EventEmitter and manually subscribing to events
EventEmitter
By implementing the EventEmitter interface
Using the @OnApplicationBootstrap() lifecycle hook
@OnApplicationBootstrap()
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
Simplified database management
Reduced need for code testing
When might you choose to use a custom decorator instead of middleware in NestJS?
When you need to perform asynchronous operations before or after a request.
When the logic you want to apply is highly specific to a single method or parameter.
When you want to modify the routing behavior of your application.
When you need access to the request or response objects within the logic.
Which NestJS module is essential for working with event emitters and listeners?
@nestjs/event-emitter
@nestjs/core
@nestjs/platform-express
@nestjs/common