개발스토리

Nest - First steps 본문

Nestjs

Nest - First steps

무루뭉 2021. 6. 25. 01:54

Nest 공식 문서를 바탕으로 정리한 게시글입니다.

 


 

디렉토리 구조

 

 


app.controller.ts

하나의 라우트가 있는 기본 컨트롤러

app.controller.spec.ts

컨트롤러를 위한 유닛 테스트

app.module.ts

애플리케이션의 루트 모듈

app.service.ts

단일 메소드를 사용하는 기본 서비스

main.ts

핵심기능 NestFactory를 사용하여 Nest 애플리케이션 인스턴스를 생성하는 애플리케이션의 엔트리 파일

 

// main.ts

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

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();

 

main.ts에는 애플리케이션을 부트스트랩하는 비동기 함수가 포함되어 있다.

간단하게 3000번 포트로 http 리스터를 실행시키는 코드가 있다.

NestFactory 클래스를 사용해서 Nest 애플리케이션 인스턴스를 생성한다.

create() 메서드는 INestApplication 인터페이스를 충족하는 애플리케이션 객체를 반환한다. 

 

Platform

 

Nest는 플랫폼에 구애받지 않는, 플랫폼 독립적인 프레임워크를 목표로 한다.

Express, Fastify 두 가지 플랫폼을 사용가능하고 디폴트는 Express이다.

const app = await NestFactory.create<NestExpressApplication>(AppModule);

위 처럼 create 함수에서 플랫폼 지정이 가능하다.

'Nestjs' 카테고리의 다른 글

Nest - Exception filters  (0) 2021.07.19
Nest - Controllers  (0) 2021.07.19
Nest - Hot Reload with CLI  (0) 2021.06.28
Nest - Introduction  (0) 2021.06.25
Comments