Which of the following is NOT a built-in Pipe provided by NestJS?
Explanation:
NestJS provides ValidationPipe, ParseIntPipe, and DefaultValuePipe as built-in solutions. There's no built-in 'TransformationPipe.'
What is the purpose of a Model in Mongoose?
Explanation:
Models in Mongoose are constructed from Schemas and provide an interface for interacting with a specific collection in your MongoDB database. They offer methods for querying, creating, updating, and deleting documents.
Which interface should a class implement to function as a Guard in NestJS?
Explanation:
The ICanActivate
interface requires a single method, canActivate
, which contains the core logic of your guard. This method returns a boolean or a Promise resolving to a boolean, indicating whether the request is allowed.
How can you access the currently authenticated user's information within a NestJS controller after successful authentication?
Explanation:
After Passport.js successfully authenticates a request, it typically attaches the user object to the request object. You can access this object as req.user
within your controller methods.
In Mongoose, what is a Schema?
Explanation:
Schemas in Mongoose define the structure of documents within a MongoDB collection. They specify the fields, data types, validation rules, and other properties for each document, providing a layer of organization and consistency.
Which interface does a logging interceptor primarily implement in NestJS to intercept incoming requests and outgoing responses for logging purposes?
Explanation:
In NestJS, logging interceptors implement the NestInterceptor
interface. This interface provides two methods: intercept()
for intercepting incoming requests and modifying responses, and catch()
for handling any exceptions that occur during the interception process.
What is a key advantage of using interceptors for cross-cutting concerns like logging and transformation in NestJS?
Explanation:
Using interceptors in NestJS for tasks like logging, caching, and transformation brings multiple benefits, including improved code organization, reduced code duplication, and potentially enhanced performance due to their centralized nature.
What decorator is used to register a caching interceptor globally in a NestJS application?
Explanation:
The @UseInterceptors(CacheInterceptor)
decorator is used to register a caching interceptor globally in a NestJS application, allowing it to intercept requests and responses for all controllers and routes.
How does NestJS facilitate database integration?
Explanation:
NestJS itself doesn't directly manage database connections. However, its modular design and decorators (like @InjectRepository
) make it easy to integrate ORMs like TypeORM or ODMs like Mongoose, allowing you to seamlessly connect to and work with your chosen database.
How does the CQRS pattern improve the design of event-driven systems?
Explanation:
CQRS optimizes event-driven systems by dividing operations into distinct commands (for changing state) and queries (for reading state), allowing for independent scaling and optimization.