What is a key advantage of using NestJS over plain Express.js for building Node.js applications?
Explanation:
NestJS promotes code reusability and maintainability through its modular structure and by leveraging TypeScript. While it's built upon Express.js, it adds a significant layer of organization and type safety.
After installing the NestJS CLI, what command is used to initiate a new NestJS project?
Explanation:
The nest new
command followed by your desired project name is the standard way to start a new NestJS project using the CLI.
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.
What is the advantage of using built-in HTTP exception filters in NestJS?
Explanation:
NestJS's built-in filters simplify error handling by providing ready-to-use responses for standard HTTP errors, reducing the need for repetitive code.
What is the default scope of a provider in NestJS?
Explanation:
In NestJS, providers are singletons by default. This means that a single instance of the provider is created and shared across the entire application.
What is the role of Providers in NestJS?
Explanation:
Providers are fundamental to NestJS's dependency injection system. They can be classes annotated with @Injectable()
, and their instances can be injected into constructors of other components, promoting code reusability and testability.
What is the purpose of the useFactory
property in a FactoryProvider
?
Explanation:
The useFactory
property in a FactoryProvider
is used to define a factory function. This function is responsible for creating and returning an instance of the provider. It can be asynchronous and can inject dependencies.
Which programming language forms the foundation of NestJS?
Explanation:
NestJS is built on top of Node.js, and it primarily uses either JavaScript or TypeScript (a superset of JavaScript) for building applications.
When using an Interceptor to modify the response, what is the best way to ensure type safety?
Explanation:
For type safety, define generics with the NestInterceptor
interface, specifying the expected request and response types, allowing TypeScript to perform type checking.
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.