Skip to content

Instantly share code, notes, and snippets.

@swiftintellij
Last active April 25, 2020 21:54
Show Gist options
  • Save swiftintellij/e679f69fce5ccb71896d3d38d13bf9a9 to your computer and use it in GitHub Desktop.
Save swiftintellij/e679f69fce5ccb71896d3d38d13bf9a9 to your computer and use it in GitHub Desktop.

Heroku 에 Nest.js 프로젝트 배포

10분만 해보기

간단한 Nest 프로젝트를 생성한 후 신용카드 없이 Node 서버를 돌려볼 수 있는 Heroku 에 배포하려고 합니다.

환경 준비

  • Nest CLI 설치
  • Horoku App 생성
  • Heroku CLI 및 로그인

Nest 프로젝트를 생성합니다.

$ nest new with-nest

Heroku 에서 구동시 필요한 포트로 수정합니다.

$ vi src/main.ts
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(process.env.PORT || 3000);
}

Heroku 에서 구동시 호출하는 스크립트 설정을 추가합니다.

$ vi package.json
…
    “prestart:prod”: “rimraf dist && npm run build”,
    “web”: “npm run start:prod”,
…
# Procfile
$ vi Procfile
web: npm run start:prod

Procfile 에 설정되어 있으면 package.json 에서 web 스크립트는 삭제해도 됩니다.

Heorku 실행 환경 설정을 합니다.

# typescript 컴파일시 devDependency 필요
$ heroku config:set NPM_CONFIG_PRODUCTION=false
$ heroku config:set NODE_ENV=production

로컬에서 실행하여 확인합니다.

$ heroku local web

정상적으로 구동된다면 Heroku Git에 커밋합니다.

$ heroku git:remote -a HEROKU_APP_ID
$ git add .
$ git commit -m “make it better”
$ git push heroku master

배포된 사이트를 확인합니다.

$ heroku open

참고

Documentation | NestJS - A progressive Node.js framework The Heroku CLI | Heroku Dev Center Deploying a Production NestJS Server on Heroku | joshmorony - Learn Ionic & Build Mobile Apps with Web Tech

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment