Junior — Middle
What components are included in a module in NestJS?
sobes.tech AI
Answer from AI
In NestJS, a module is the main building block of an application that groups related components. A module typically includes:
- Controllers — classes that handle incoming HTTP requests and return responses.
- Providers — services and other classes that are injected and provide business logic.
- Imports — other modules necessary for the current module to function.
- Exports — components (usually providers) that the module makes available to other modules.
Example of a module:
import { Module } from '@nestjs/common';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
@Module({
controllers: [UsersController],
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}
Thus, the module organizes the application's structure, ensuring encapsulation and reusability of components.