본문 바로가기

개발/Nest.js

[Nest.js] Nest.js 설치

전체적인 내용은 Nest.js 정식 Documentation을 참고하여 만들었다.

 

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

 

 

우선 시작하기에 앞서 Node.js 가 설치가 되어 있지 않다면 아래 사이트에서 설치를 진행해야한다.

 

다운로드 | Node.js

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

nodejs.org

이미 설치가 되어 있는 사람은 참고할 필요 없다. 참고로 난 2023. 01. 27. LTS 버전인 18.13.0 을 다운 받았다.

 

설치

우선 nest.js 를 다운받아야한다.

npm install -g @nestjs/cli
nest new {project-name}

여기서는 두 가지 문제가 발생했는데

 

  1. 'npm’ 을 찾을 수 없다 라고 뜸.
    • node 설치 전 CLI나 Editor를 켰을 때 시스템 환경 변수가 설정되기 전이라 재부팅 후에 정상적으로 작동한다.
  2. ‘nest’ 명령어를 실행할 수 없다고 뜸.
    • 해당 블로그를 참고하여 Windows 권한을 변경해주었더니 실행되었다!
 

[error] VSCode 오류(이 시스템에서 스크립트를 실행할 수 없으므로 ~ps1 파일을 로드할 수 없음)

nodemon : 이 시스템에서 스크립트를 실행할 수 없으므로 C:\Users\sunho\AppData\Roaming\npm\nodemon.ps1 파일을 로드할 수 없습니다. 자세한 내용은 about_Execution_Policies(https://go.microsoft.com/fwlink/?LinkID=135170)를

prefer2.tistory.com

 

실행

바로 실행해보았다.

npm run start

실행 이미지

포트 설정을 하지 않고 바로 실행했을 경우 기본적으로 3000번 포트를 사용한다.

이미 3000번 포트를 사용하고 있다면 /src/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); //A
}
bootstrap();

A 부분의 3000을 다른 포트로 변경하면 된다.

'개발 > Nest.js' 카테고리의 다른 글

[Nest.js] Nest.js Basic CRUD 만들기 - 2  (0) 2023.01.31
[Nest.js] Nest.js Basic CRUD 만들기 - 1  (0) 2023.01.28