nest.js 모듈이란?
- App Module 안에 BoardModule, AuthModule이 있다.
- 모듈은 @Module() 데코레이터로 주석이 달린 클래스이다.
- 각 프로그램에는 적어도 하나의 모듈이 있다.
- 밀접하게 관련된 기능 집합으로 구성 요소를 구성하는 효과적인 방법이다.
- 같은 기능에 해당하는 것들은 하나의 모듈 폴더 안에 넣어서 사용한다.
- 싱글톤이므로, 여러 모듈간에 쉽게 공급자의 동일한 인스턴스를 공유할 수 있다.
모듈 생성하기
npx nest g module 모듈명
명령어를 통해 모듈 생성
Controllers 이란?
- 컨트롤러(Controllers)는 들어오는 요청을 처리하고 클라이언트에 응답을 반환한다.
- Controller는
@Controller
데코레이터로 클래스를 데코레이션하여 정의된다.
- 인자를 Controller로 의해서 처리되는 “경로”로 받는다.
Handler 란?
- 핸들러(Handler)는
@Get
, @Post
, @Delete
등과 같은 데코레이터로 장식된 컨트롤러 클래스 내의 단순한 메소드이다.
BoardController 생성하기
npx nest g controller 컨트롤러 이름 --no-spec
을 사용하여 BoardController를 생성한다.
--no-spec
은 테스트 코드를 만들지 않겠다는 의미이다.