What is the primary function of middleware in NestJS?
To define API routes.
To handle database operations.
To render dynamic views on the server.
To intercept and modify incoming requests and outgoing responses.
What is the primary purpose of exception handling in a NestJS backend application?
To handle database migrations and schema changes.
To define middleware functions for request-response cycles.
To enforce strict data typing in controller methods.
To gracefully handle and respond to unexpected errors during request processing.
Can a Controller access a Service's methods in NestJS?
Yes, by using static methods of the Service.
No, Controllers and Services are completely isolated.
Yes, by injecting the Service into the Controller's constructor.
Only if the Controller and Service are defined in the same module.
Which decorator is used to define an Interceptor class in NestJS?
@Interceptor()
@Controller()
@Injectable()
@Module()
What is the purpose of the return statement in a NestJS controller method?
return
To define the route path
To handle errors within the route
To specify middleware for the route
To send the response to the client
Which interface does a custom exception filter in NestJS need to implement?
CanActivate
HttpException
Injectable
ExceptionFilter
What is the primary purpose of using Interceptors in NestJS?
To handle database queries.
To create reusable UI components.
To intercept and modify incoming requests or outgoing responses.
To define routes for API endpoints.
How does NestJS simplify unit testing of your application's components?
NestJS applications do not require unit tests due to their strict architecture
NestJS's modular structure and dependency injection make it easy to isolate and test individual components
NestJS has built-in tools that automatically generate unit tests
NestJS relies entirely on end-to-end testing, making unit tests unnecessary
How can you transform the data returned from a controller method using an Interceptor?
By directly modifying the controller method's return value.
By calling a service method within the Interceptor.
By using RxJS operators on the Observable returned by next.handle().
next.handle()
By modifying the ctx.body property.
ctx.body
What is the difference between a provider and a service in NestJS?
Providers are used for database operations, while services handle business logic.
Providers and services are essentially the same thing, with no real distinction.
Providers are classes that can be injected as dependencies, while a service is a specific type of provider with business logic.
Providers are decorated with @Injectable(), while services are decorated with @Service().