코딩일상

[nest.js] CLI 이용하여 파일 및 폴더 생성방법 본문

개발 공부/nest.js

[nest.js] CLI 이용하여 파일 및 폴더 생성방법

solutionMan 2022. 12. 5. 12:09
반응형

nest.js에서 모듈 파일을 생성하는 방법 

 

CLI를 이용하여 손쉽고 안전하게 파일과 폴더를 만들어낼 수 있다.

 

*아래 내용들은 nest.js document를 참고하여 작성하였습니다.

1. 모듈 파일 생성 방법

nest generate

Generates and/or modifies files based on a schematic

$ nest new <name> [options]
$ nest n <name> [options]

 $ nest g mo cats

 

사용하는 이유

그냥 폴더를 만들어도 되지만 CLI명령어를 사용하면 app.module.ts에서 7번째 줄에 보면 module에 자동으로 들어가게 된다.

에러 방지를 하는데 기여할 수 있음

 

 

 

2. 컨트롤러 파일 생성 방법

$ nest g co cats

위 명령어를 사용하면 cats 폴더에 컨트롤러가 생기고 모듈에도 자동으로 반영이 된다.

 

3. 서비스 파일  생성 방법

위 방법들과 동일하며 적용되는 결과도 위와 같다.

$ nest g service cats

 

최종 파일 구성된 모습

결론

위와 같이 CLI를 이용하여 우리가 원하는 형태의 파일을 손쉽고 안전하게 생성해낼 수 있다.

 

Documentation | NestJS - A progressive Node.js framework

Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac

docs.nestjs.com

 

반응형
Comments