코딩일상

[nest.js] nest.js 첫 시작(first step) 본문

개발 공부/nest.js

[nest.js] nest.js 첫 시작(first step)

solutionMan 2022. 12. 2. 01:17
반응형

nest.js 공식문서를 최대한 참고하여진행하였다.

 

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

1.nest.js를 설치할 폴더로 들어간다.

$ npm i -g @nestjs/cli
$ nest new project-name

2.설치 방식을 선택(npm 과 yaran방식 중 선택)

나는 npm을  방식을 택하여서 하였다. 

이유) 공식문서에서 npm을 사용하여서 진행하였기 때문에

 

nest.js에서 기본적으로 필요한 세팅들이 자동으로 모두 설치가 된다. 

 

package.json에 들어가면 nest.js에 핵심적으로 필요한것들이 들어가 있다.

일단 자주 사용할 명령어는  start:dev(개발환경에서 실행)/ start:debug(디버깅할 때)/ start:prod(배포)를 사용할것이다.

 

app.controller.spec.ts는 app.controller을 테스트 하기위한 파일

test라는 폴더도 프로젝트를 test하기위해 생긴 폴더

 

src폴더구성과 파일 별 역할

각각의 파일에 대한 설명은 nest.js document에도 설명이되어있다.

 

3.프로젝트 시작

$ npm run start:dev

위 명령어를 시작하면 아래와같은 결과들을 확인 할 수 있다.

포스트맨으로 요청을 보내게 되면 "Hello World"라는 값을 받게된다.

 

4."Hello World"는 어디서 나왔을까??

우리는 GET요청을 localhost로 주소로 보냈다.

우선 main.ts에서 app에 할당되어지는 값  AppModule로 이동

AppModule에서 AppControlller로 이동을 하게된다.

그후 우리는 GET요청을 받은거이니 10번째 줄에서 app.Service의 메소드 getHello가 실행된다.

app.Service에서  getHello 메소들를 6번줄을 보면 "Hello World"를 반환한다.

 

위의 과정을 거쳐서 우리는 "Hello World"라는 결과값을 받게된것이다.

반응형
Comments