[NestJS] 윈도우 NestJS 개발환경 - 리눅스 Ubuntu NestJS 개발 환경 > Node/Flutter/Dart

본문 바로가기

사이트 내 전체검색

Node/Flutter/Dart

[NestJS] 윈도우 NestJS 개발환경 - 리눅스 Ubuntu NestJS 개발 환경

작성일 24-05-02 22:39

페이지 정보

작성자sbLAB 조회 40회 댓글 0건

본문

 윈도우 10 NestJS 개발환경 

https://nodejs.org/en/download

node-v20.12.2-x64.msi 설치 -> 예) D:\nodejs

cmd 터미널 이동

$ npm -v

$ node -v

-----------

v20.12.2

-----------

[NestJS 설치] - https://docs.nestjs.com/

$ npm i -g @nestjs/cli 

$ nest -v

--------

10.3.2

------

$ nest new project-name

패키지매니저는 npm 으로 선택(Which package manager would you ❤️  to use? npm)


[NestJS 패키지들 최신버전으로 업데이트]

project-name 폴더로 이동 -> D:\project-name>

D:\project-name 프로젝트 루트 폴더에서


$ npm i -g npm-check-updates


$ ncu -u -f /^@nestjs/   <- @nestjs 만 최신 버전체크

--------------------------------------------

@nestjs/cli               ^10.0.0  →  ^10.3.2

 @nestjs/common        ^10.0.0  →  ^10.3.8

 @nestjs/core            ^10.0.0  →  ^10.3.8

 @nestjs/platform-express  ^10.0.0  →  ^10.3.8

 @nestjs/schematics     ^10.0.0  →  ^10.1.1

 @nestjs/testing          ^10.0.0  →  ^10.3.8

---------------------------------------------

 

[기존 패키지 정보파일과 라이브러리 디렉토리(node_modules) 삭제]

$ del package-lock.json

$ rmdir node_modules /s


[위에서 업데이트된 package.json 환경으로 패키지 재설치]

$ npm install

---------------------------------------------------------------



 리눅스 Ubuntu NestJS 개발환경  


※ 필요시 기존 nodejs /  npm 삭제(참고용)

---------------------------

# sudo apt-get remove nodejs

# sudo apt-get remove npm

----------------------------


[sudo 권한]

# apt update 하고 Ubuntu 기본 저장소에 있는 구버전의 nodejs 설치하면 NestJS 연결시 오류남(최신버전 설치 필요).

sudo apt-get install nodejs (X) 


# 아래처럼 최신버전의 nodejs 설치

https://deb.nodesource.com/  접속 최신 nodejs 버전확인 및 사이트 안내에 따라 아래처럼 설치

# curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -

# sudo apt-get install -y nodejs


※설치중 dpkg Error가 나면 아래 실행

# sudo dpkg --remove --force-remove-reinstreq libnode-dev

# sudo dpkg --remove --force-remove-reinstreq libnode72:amd64


# node -v

---------

v20.12.2

---------

[npm설치]

# npm i -g @nestjs/cli   


# npm -v

-------

10.5.0

-------


# nest -v

-----------

10.3.2

-----------


[프로젝트 생성]

project-name 의 프로젝트 디렉토리가 생성될 경로로 이동

# nest new project-name

- 패키지 매니저는 npm 으로 선택(Which package manager would you ♡  to use? npm)


[NestJS 패키지들 최신버전으로 업데이트]

project-name 폴더안으로 이동 -> 예) var/www/project-name

# cd project-name


프로젝트 루트폴더(var/www/project-name 안)에서

# npm i -g npm-check-updates

# ncu -u -f /^@nestjs/  <- @nestjs 만 최신 버전체크


----------------------------------------------------

@nestjs/cli               ^10.0.0  →  ^10.3.2

 @nestjs/common            ^10.0.0  →  ^10.3.8

 @nestjs/core              ^10.0.0  →  ^10.3.8

 @nestjs/platform-express  ^10.0.0  →  ^10.3.8

 @nestjs/schematics        ^10.0.0  →  ^10.1.1

 @nestjs/testing           ^10.0.0  →  ^10.3.8

-----------------------------------------------------

 

[기존 패키지 정보파일과 라이브러리 디렉토리(node_modules) 삭제]

# rm package-lock.json  <- 최신 패키지가 적용된 lock 파일 새로 생성하기위해 삭제

# rm -r node_modules   <- 최신 node_modules  을 새로 다운 받기위해 삭제


https://hyunjun19.github.io/2018/03/23/package-lock-why-need/ 


[위에서 최신버전 정보로 업데이트된 package.json 환경(의존성)으로 패키지 재설치]

# npm install


# npm start  (= nest start)


[외부에서 접속할 경우 리눅스서버 3000포트 허용]

# ufw allow 3000


http://localhost:3000/ 로 접속 확인


※실제 운용서버는 Nginx 서버아래 reverse proxy 로 localhost:3000 연결 사용


server {
    listen 443 ssl;
    ...
    ...
#root /
location / {
proxy_pass http://localhost:3000;
}
}

위와 같이 사용!

아래는 특정 경로 지정할때(비권장)

  server {
      listen 443 ssl;
      ...
      ...
  #nest/~
  location /nest/ {
  proxy_pass http://localhost:3000/;
  }
  }


 추가 설정 

NestJS Essential Extension Pack 

https://marketplace.visualstudio.com/items?itemName=imgildev.vscode-nestjs-pack 

위 확장팩 설치 후 Error Lens / ESLint / indent-rainbow 플러그인 등 선택적으로 disable
 

NestJS Hot Reload 

https://docs.nestjs.com/recipes/hot-reload#hot-reload 

위 기능을 사용하지 않고(원인을 알수 없으나 수정 소스 적용까지 지연있음) 

# npm run start:dev  로 실시간 소스 수정 적용가능. <- 권장!


 
[package.json]
"scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:reload": "nest build --webpack --webpackPath webpack-hmr.config.js --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
 


※ ESLint Delete `␍` eslint (prettier/prettier) 문제 제거

[.eslintrc.js]
...
  rules: {
    '@typescript-eslint/interface-name-prefix': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    "prettier/prettier": [ "error",  { "endOfLine": "auto" }],
  },
};


VCode - Termial 에서 nest 실행에러날때 -> Windows PowerShell(관리자 권한으로 실행) -> 

$ get-help Set-ExecutionPolicy

$ Set-ExecutionPolicy RemoteSigned 







댓글목록

등록된 댓글이 없습니다.

Copyright © 소유하신 도메인. All rights reserved.
PC 버전으로 보기