[Nest] 01. Install & Setting

단님·2022년 12월 9일

nest

목록 보기
1/1

프론트 코드 작업에 앞서 간단한 NestJS 연습을 해보려합니다.

1. Init

아래에서 패키지 매니저는 pnpm 으로 설정하지만 사용하고 싶은 걸 사용합니다.

# gloabl cli 설치
$ npm i -g @nestjs/cli

# "nest-template" project 생성
$ nest new nest-template
? Which package manager would you ❤️  to use? 
  npm
  yarn
> pnpm

# 실행
$ cd nest-template
$ pnpm start:dev
[Nest] ... LOG [NestApplication] ... successfully started

2. Fastify

Nestexpress를 기본적으로 지원하지만 fastify와의 호환성도 제공합니다. 높은 성능으로 유행하고 있는 fastify를 사용해보도록 하겠습니다.

$ pnpm i --save @nestjs/platform-fastify

# "Issues with peer dependencies found" warning이 발생할 경우 다음을 입력해주세요.
$ pnpm config set auto-install-peers true

이후 main.ts를 아래와 같이 수정해주세요.

// 타입 명시 및 httpAdapter를 fastify로 설정
async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter(),
  );
  await app.listen(3000);
}
bootstrap();

포스트맨에서 확인해봅니다.

[GET] http://localhost:3000
Hello World!
profile
코딩하는 단님

0개의 댓글