What is NOT a benefit of using Dependency Injection in NestJS?
Explanation:
Dependency Injection promotes loose coupling, not increased coupling. It allows components to depend on abstractions (interfaces) rather than concrete implementations.
What is the purpose of the @Res()
decorator in NestJS?
Explanation:
The @Res()
decorator provides access to the underlying Express response object, allowing for manual manipulation of the response, such as setting headers or sending custom status codes.
Which decorator is associated with removing resources in RESTful APIs?
Explanation:
The @Delete()
decorator signifies that a controller method handles HTTP DELETE requests, used for removing resources from the server.
What is the role of the 'main.ts' file in a NestJS project?
Explanation:
The main.ts
file is the entry point of your NestJS application. It bootstraps the NestJS application, often setting up the listening port and other core configurations.
What is the role of the app.module.ts
file in a NestJS application?
Explanation:
The app.module.ts
file is the entry point of a NestJS application. It bootstraps the application and typically imports other modules, forming the application's dependency tree.
Which interface does a custom exception filter in NestJS need to implement?
Explanation:
The ExceptionFilter
interface ensures that your custom filter class has the necessary catch()
method for handling exceptions.
What is the primary purpose of exception handling in a NestJS backend application?
Explanation:
Exception handling is crucial for preventing application crashes and providing meaningful error responses to clients when unexpected situations arise during request handling.
How does NestJS simplify unit testing of your application's components?
Explanation:
The clear separation of concerns and the use of dependency injection in NestJS make it straightforward to mock dependencies and write focused unit tests for individual components.
How do you access query parameters in a NestJS controller method?
Explanation:
The @Query()
decorator provides access to query parameters within a controller method. It allows you to retrieve values passed as key-value pairs in the URL's query string.
How can you access the currently logged-in user within your middleware in NestJS?
Explanation:
If you're using an authentication middleware in NestJS, it typically attaches the authenticated user object to the request object. You can access this user information within your middleware by referring to req.user
.