Skip to content

Nest 구조

top-chaser edited this page Nov 27, 2023 · 1 revision

Nest Module

Module 이란?

  • 모듈은 @Module {} 데코레이터로 주석이 달린 클래스로, 어플리케이션 구조를 구성하는데 사용하는 메타 데이터를 제공한다.
  • 각 응용 프로그램에는 하나 이상의 모듈이 존재하며, 루트 모듈은 Nest가 사용하는 시작점이 된다.

Module 생성하기

nest g module 모듈 이름

NestJs Controller

Controller 란?

컨트롤러는 들어오는 요청을 처리하고 클라이언트 응답을 반환한다.

@Controller 데코레이터로 클래스를 데코레이션하여 정의된다.

Handler 란?

@Get@Post@Delete와 같은 데코레이터로 장식된 컨트롤러 클래스 내의 단순한 메소드이다.

Controller 생성하기

nest g controller 컨트롤러 이름 --no-spec

NestJS Service(Providers)

Provider / Service 란?

Provider는 Nest의 기본개념이다. Controller가 필요로 하는 컴포넌트들이 기능 단위로 존재하고, Controller가 해당 컴포넌트를 필요로 할 때 그 컴포넌트를 Controller로 종속시켜주는 것을 주입이라고 하는데, 여기서 각 요소가 Provider가 된다. 우리는 Service를 Controller에 주입시키기 때문에, Service는 큰 의미로 Provider이다.

Service 생성하기

nest g service 서비스 이름 --no-spec
Clone this wiki locally