NestJS Research & Evidence-Based Practice 2 — Questions and Answers
Question 1: When researching NestJS interceptors, you find they implement which interface to handle request/response transformation?
- NestMiddleware
- NestInterceptor (Correct answer)
- CanActivate
- PipeTransform
Correct answer: NestInterceptor
NestInterceptor is the interface that interceptors must implement, providing the intercept() method with access to the execution context and call handler.
Question 2: Based on NestJS documentation, which decorator is used to bind a specific interceptor to a single route handler rather than the entire controller?
- @UseGuards()
- @UsePipes()
- @UseInterceptors() (Correct answer)
- @UseFilters()
Correct answer: @UseInterceptors()
@UseInterceptors() can be applied at the method level to scope an interceptor to a single route handler.
Question 3: Evidence from NestJS performance benchmarks suggests that which caching strategy is natively supported via @nestjs/cache-manager?
- Write-through caching
- Read-through caching with in-memory store (Correct answer)
- Write-behind caching
- Cache-aside with Redis only
Correct answer: Read-through caching with in-memory store
@nestjs/cache-manager provides read-through caching with an in-memory store by default, and supports Redis via additional adapters.
Question 4: When reviewing NestJS CLI documentation, which command generates a complete CRUD resource with controller, service, module, and DTO files?
- nest generate module
- nest generate class
- nest generate resource (Correct answer)
- nest generate controller
Correct answer: nest generate resource
nest generate resource (or nest g res) scaffolds a full CRUD resource including controller, service, module, DTOs, and entity files.
Question 5: Research into NestJS dependency injection shows that which scope causes a new provider instance to be created for every incoming request?
- DEFAULT
- SINGLETON
- REQUEST (Correct answer)
- TRANSIENT
Correct answer: REQUEST
REQUEST scope creates a new instance of the provider for each incoming HTTP request, which is useful for request-scoped state.
Question 6: Based on NestJS Guards documentation, a guard must implement which method that returns a boolean or Observable<boolean> to allow or deny access?
- handle()
- intercept()
- canActivate() (Correct answer)
- transform()
Correct answer: canActivate()
Guards implement the canActivate() method from the CanActivate interface, returning true to allow or false/exception to deny the request.
Question 7: When investigating NestJS exception filters, which built-in filter handles all unhandled exceptions and returns a standard JSON error response?
- GlobalFilter
- HttpExceptionFilter
- BaseExceptionFilter (Correct answer)
- AllExceptionsFilter
Correct answer: BaseExceptionFilter
The BaseExceptionFilter is the built-in global exception filter that catches unhandled exceptions and transforms them into HTTP responses.
When researching NestJS interceptors, you find they implement which interface to handle request/response transformation?