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 implement custom error handling logic for a specific HTTP exception type.
To handle exceptions specific to a particular controller or route.
How do you register a global exception filter in NestJS?
By using the useGlobalFilters() method in the main.ts file.
useGlobalFilters()
main.ts
By using the @Catch() decorator on the global filter class.
@Catch()
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()
What is the purpose of the 'transport' option when creating a NestJS microservice?
Configuring the user interface
Defining the database connection
Setting the logging level
Specifying the communication protocol (e.g., TCP, Redis)
In JWT authentication, what does JWT stand for?
Java Web Token
JavaScript Web Token
Just Write Tests
JSON Web Token
How does NestJS facilitate database integration?
NestJS provides a modular structure and decorators to integrate various database solutions
NestJS only supports relational databases and not NoSQL databases
NestJS automatically configures database connections without any additional code
NestJS prevents the use of external libraries like TypeORM or Mongoose
What is the primary testing framework used for unit testing in NestJS?
Jest
Mocha
Chai
Jasmine
In a NestJS application using CQRS, what is the role of a command handler?
To emit events in response to user actions
To handle errors and exceptions within event listeners
To retrieve data from the database based on a query
To process incoming events and update the application state
What is the advantage of using a dedicated session store (like Redis) over in-memory storage for sessions in a production NestJS application?
Enhanced security for sensitive data
Simplified development setup
Scalability and session persistence across multiple server instances
Improved code readability
What is the recommended approach to unit test a custom Guard in NestJS?
By mocking external dependencies like database calls or HTTP requests, focusing on testing the Guard's logic in isolation.
By relying solely on console logs within the Guard's code to verify its behavior.
By manually triggering API requests using tools like Postman and observing the responses.
By setting up a complete end-to-end testing environment that interacts with real databases and services.
How can you apply a transformation interceptor to a specific method in a controller in NestJS?
By using the @UseInterceptors() decorator at the method level
@UseInterceptors()
By registering the interceptor globally in the app.module.ts file
app.module.ts
By extending the BaseController class and applying the interceptor in the constructor
BaseController
By using the @Transform() decorator above the controller class
@Transform()