I am trying to deploy my NestJS application to AWS elastic beanstalk, but did not had any success, can someone please write step by step how can I achieve that?
Full explanation:
I have a nestjs app with typeorm but didn’t configured it to work with RDS, so we will leave it for now (maybe there is a connection, idk).
First of all I made a CodePipline that when I am pushing new version to my github repo it automatically deploying the whole repo to my eb instance that works on node 12.x.
Now, I want that on every git push, the instance will install the dependencies, build the nest app, and start the server from the /dist/main.js.
I have added a Procfile with:
web: npm install && npm run build && npm run start:prod
I have also added PORT environment variable on EB that configured on main.ts and when not found to use 8080.
And my package.json scripts are like a newly created nest app:
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write "src/**/*.ts" "test/**/*.ts"",
"start": "nest start",
"start:dev": "nest start --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"
}
When deploying I see in the logs that it did something like this:
Jan 23 20:01:14 web: > [email protected] start /var/app/current
Jan 23 20:01:14 ip-172-31-17-171 web: > sudo npm i -g @nestjs/cli && node dist/main
Jan 23 20:01:14 web: We trust you have received the usual lecture from the local System
Jan 23 20:01:14 web: Administrator. It usually boils down to these three things:
Jan 23 20:01:14 web: #1) Respect the privacy of others.
Jan 23 20:01:14 web: #2) Think before you type.
Jan 23 20:01:14 web: #3) With great power comes great responsibility.
Jan 23 20:01:14 web: sudo: no tty present and no askpass program specified
Jan 23 20:01:14 web: npm ERR! code ELIFECYCLE
Jan 23 20:01:14 web: npm ERR! errno 1
Jan 23 20:01:14 web: npm ERR! [email protected] start: `sudo npm i -g @nestjs/cli && node dist/main`
Jan 23 20:01:14 web: npm ERR! Exit status 1
Jan 23 20:01:14 web: npm ERR!
Jan 23 20:01:14 web: npm ERR! Failed at the [email protected] start script.
So I am getting 502 when entering the env url.
So maybe it is a permission issue with npm? Or I need to deploy on some way only the /dist folder?
What do you think the problem is?
It is my first time trying to deploy a backend server to eb :)
question from:
https://stackoverflow.com/questions/65864374/deploying-nestjs-application-on-elastic-beanstalk