NestJS Modules

NestJS Modules

NestJS Modules

Root Module 루트 모듈은 Nest가 애플리케이션 그래프(Nest가 module 과 Provider의 relationship & dependencies를 해결하는데 사용되는 내부 date 구조)를 구축하는데 사용하는 시작점이다.

대부분의 애플리케이션에서 결과 아키텍처는 여러 모듈을 사용하며 각 모듈은 밀접하게 관련된 기능 세트를 캡슐화합니다.

Module의 구성

providers Nest 인젝터에 의해 instantiated되고 적어도 이 모듈 전체에서 공유될 수 있는 공급자
controllers 인스턴스화되어야 하는 이 모듈에 정의된 Controller
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 (provide value)
외부로 Module을 내보낼 때 사용한다.

Feature Module

→ 특히 애플리케이션 및/또는 팀의 규모가 커짐에 따라 복잡성을 관리하고 SOLID 원칙으로 개발하는 데 도움이 됩니다.

Ex) Cats Module 구성