Which module is essential for implementing JWT authentication in a NestJS application?
Explanation:
The @nestjs/jwt
module provides the necessary utilities for signing, verifying, and handling JWTs in a NestJS application. This includes the JwtService
for creating tokens and guards for protecting routes.
How do you register a global exception filter in NestJS?
Explanation:
You register a global exception filter using the useGlobalFilters()
method provided by the NestJS application instance in your main.ts
file. This ensures the filter is applied globally.
Which testing type provides the most comprehensive coverage by simulating real user interactions with a running NestJS application?
Explanation:
E2E tests act like real users, interacting with the application through the UI (if one exists) or API endpoints to validate the entire system's behavior.
What is the correct way to apply multiple decorators to a single target in NestJS?
Explanation:
In TypeScript (and therefore NestJS), you apply multiple decorators by listing them within square brackets above the decorated element.
What object in the intercept()
method of a transformation interceptor allows you to modify the response stream?
Explanation:
Within a transformation interceptor's intercept()
method, you use context.switchToHttp().getResponse()
to access and modify the response stream before it's sent back to the client.
What is a common use case for a class decorator in NestJS?
Explanation:
Class decorators are well-suited for modifying the prototype of a class, effectively adding shared properties or methods to every object instantiated from that class.
Why is it generally advisable to have a balance of different testing types (unit, integration, E2E) in a NestJS project?
Explanation:
A combination of testing types ensures that individual units, their interactions, and the overall system behavior are all thoroughly validated.
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.
When should you use a global exception filter in NestJS?
Explanation:
Global exception filters provide a centralized place to handle uncaught exceptions in your NestJS application. This promotes code reusability and a consistent error response format.
What is a common approach to ensure data consistency when using CQRS and event-driven architecture in NestJS?
Explanation:
Eventual consistency is a common strategy in CQRS, where changes are reflected in read models (used for queries) asynchronously after the command is processed and events are emitted.