Module
The @module() decorator provides metadata that Nest makes use of to organize the application structure.
일반적으로 모듈이라고 하면 조그만 클래스나 함수처럼 한 가지 일만 수행하는 소프트웨어 컴포넌트가 아니라 여러 컴포넌트를 조합하여 좀 더 큰 작업을 수행할 수 있게 하는 단위를 말한다.
The @Module() decorator takes a single object whose properties describe the module:
providers | the providers that will be instantiated by the Nest injector and that may be shared at least across this module. |
controllers | the set of controllers defined in this module which have to be instantiated |
imports | the list of imported modules that export the providers which are required in this module |
exports | the subset of providers that are provided by this module and should be available in other modules which import this module. You can use either the provider itself or just its token |
동적 모듈
동적 모듈(dynamic module)은 모듈이 생성될 때 동적으로 어떠한 변수들이 정해진다. 즉, 호스트 모듈(프로바이더나 컨트롤러와 같은 컴포넌트를 제공하는 모듈)을 가져다 쓰는 소비 모듈에서 호스트 모듈을 생성할 때 동적으로 값을 설정하는 방식
Nest에서 제공하는 Config 패키지
@nestjs/config에서는 ConfigModule 이름을 가진 모듈이 이미 존재한다. 이 모듈을 동적 모듈로 가져온다. 정적 모듈을 가져올 때와 달리 ConfigModule.forRoot() 메서드를 호출한다. forRoot 메서드는 DynamicModule을 리턴하는 정적 메서드이다. 인수로는 ConfigModuleOptions를 받는다. 즉, ConfigModule은 소비 모듈이 원하는 옵션값을 전달하여 원하는 대로 동적으로 ConfigModule을 생성한다.
'Web > NestJS' 카테고리의 다른 글
Provider (0) | 2024.02.20 |
---|---|
Exploring EcmaScript Decorators (0) | 2024.02.15 |
Controllers (0) | 2024.02.15 |
댓글