What is a common use case for a class decorator in NestJS?
Adding common properties or methods to all instances of a class.
Modifying the response sent back to the client.
Validating the structure of request payloads.
Defining custom route paths for controller methods.
What is the purpose of the 'transport' option when creating a NestJS microservice?
Specifying the communication protocol (e.g., TCP, Redis)
Configuring the user interface
Defining the database connection
Setting the logging level
How does the CQRS pattern improve the design of event-driven systems?
By separating read and write operations for better performance and scalability
By enforcing synchronous communication between components
By simplifying the handling of complex events
By eliminating the need for event listeners
How do you activate a custom Guard globally in a NestJS application?
By using the @Global() decorator before the guard class definition.
@Global()
By registering the guard in the providers array of the module where it's defined.
providers
By manually adding the guard to each route handler where it's needed.
By defining the guard within the main.ts file of your application.
main.ts
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.
What is the primary testing framework used for unit testing in NestJS?
Jasmine
Mocha
Chai
Jest
Can you have both global and custom HTTP exception filters in a NestJS application?
Yes, but you need to explicitly specify the order in which they should be executed.
No, global exception filters take precedence and override any custom filters.
No, NestJS only allows you to define either global or custom exception filters, not both.
Yes, but custom filters will only handle exceptions not caught by global filters.
What is the recommended approach for handling exceptions in a production-ready NestJS application?
Use a combination of global and custom exception filters for a layered approach.
Implement only global exception filters for a centralized approach.
Disable exception handling altogether for optimal performance.
Rely solely on the default NestJS error handling mechanism.
When should you use a global exception filter in NestJS?
To centralize error handling logic for exceptions thrown across your entire application.
To prevent any exceptions from being thrown in a production environment.
To handle exceptions specific to a particular controller or route.
To implement custom error handling logic for a specific HTTP exception type.
In the context of NestJS testing, what are 'mocks' primarily used for?
Replacing external dependencies with controlled implementations
Generating code coverage reports
Automating user interactions with the application's UI
Measuring the performance of specific code segments