NestJS 시작하기

Hyein·2023년 11월 7일

NestJS 시작하기

목록 보기
1/4
post-thumbnail

Nest 프로젝트 생성

Nest cli 설치 후 nest 명령어 사용

npm i -g @nestjs/cli  // nest cli 설치

nest new [프로젝트명] // 프로젝트 생성

서버 실행

package.json 내의 script를 확인하고 사용하도록 하자.

// package.json

"build": "nest build",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
yarn start:dev

포트번호 3000번이 이미 실행 중일 때

현재 필자는 프론트엔드 프로젝트를 함께 진행중이기에 3000번 포트를 이미 사용하고 있다.
따라서 nest 프로젝트는 8000번 포트를 리스닝하도록 했다.

main.ts에서 포트번호를 3000에서 8000으로 바꾸어 실행시키면 된다.

// main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(8000);  // 포트번호 변경!!!
}
bootstrap();

0개의 댓글