@Module({
imports: [DatabaseModule],
controllers: [CatsController],
providers: [CatsService],
exports: [CatsService],
})
export class CatsModule {}
The four properties are providers, controllers, imports and exports:
providerslists the classes (or custom providers) that the Nest injector creates for this module. By default, they are private to the module.controllerslists the controllers this module defines. Nest creates them and registers their routes.importslists other modules whose exported providers this module needs.exportsis the part of this module's providers (or imported modules) that other modules can use when they import this module.
How they relate: the rule is encapsulation. A provider can only be injected inside its own module, unless the module exports it. The module that wants to use it must also import the module that exports it.
providersare created by the injector and are private by default.controllersare the route handlers that the module owns.importslists the modules whose exports this module uses.exportsis the public API that other modules can inject.
Read more
- Modules (https://docs.nestjs.com/modules)docs.nestjs.com