What is the correct way to apply multiple decorators to a single target in NestJS?
By chaining the decorator functions together using the . operator.
.
By passing multiple decorator functions as arguments to the target.
By using the @ApplyDecorators function provided by NestJS.
@ApplyDecorators
By placing the decorator names within square brackets [] above the target.
[]
How does NestJS facilitate database integration?
NestJS prevents the use of external libraries like TypeORM or Mongoose
NestJS only supports relational databases and not NoSQL databases
NestJS automatically configures database connections without any additional code
NestJS provides a modular structure and decorators to integrate various database solutions
In a NestJS application using CQRS, what is the role of a command handler?
To process incoming events and update the application state
To emit events in response to user actions
To retrieve data from the database based on a query
To handle errors and exceptions within event listeners
What is the recommended approach to unit test a custom Guard in NestJS?
By relying solely on console logs within the Guard's code to verify its behavior.
By mocking external dependencies like database calls or HTTP requests, focusing on testing the Guard's logic in isolation.
By setting up a complete end-to-end testing environment that interacts with real databases and services.
By manually triggering API requests using tools like Postman and observing the responses.
What is the primary function of a Pipe in NestJS?
To define middleware for routing HTTP requests.
To manage dependency injection within the application.
To transform input data into the desired format.
To handle database queries and operations.
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 defining the guard within the main.ts file of your application.
main.ts
By manually adding the guard to each route handler where it's needed.
What is a common way to implement Role-Based Access Control (RBAC) in NestJS Guards?
By directly embedding complex SQL queries within the Guard's canActivate method.
canActivate
By retrieving user roles from the database and checking if they match the roles required to access the protected route.
By defining access rules in a separate JSON file and parsing it within the Guard.
By using a library like Passport.js to offload all authentication and authorization logic.
In NestJS, which decorator is used to define a microservice?
@Injectable()
@Controller()
@Microservice()
@Module()
What is the primary security concern associated with storing session data in cookies?
Cross-site scripting (XSS) attacks
Database injection attacks
Denial-of-service (DoS) attacks
Cross-site request forgery (CSRF) attacks
Why is it generally advisable to have a balance of different testing types (unit, integration, E2E) in a NestJS project?
To eliminate the possibility of introducing bugs during development entirely
To minimize the execution time of the entire test suite
To reduce the need for manual testing efforts completely
To ensure comprehensive test coverage across different levels of the application