title: Deploying NestJS application on Elastic Beanstalk
body: <p>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?</p>
  <p><strong>Full explanation:</strong></p>
  <p>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).</p>
  <p>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.</p>
  <p>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.</p>
  <p>I have added a Procfile with:</p>
  <pre><code>web: npm install &amp;&amp; npm run build &amp;&amp; npm run start:prod
  </code></pre>
  <p>I have also added PORT environment variable on EB that configured on main.ts and when not found to use 8080.</p>
  <p>And my package.json scripts are like a newly created nest app:</p>
  <pre><code>  &quot;scripts&quot;: {
      &quot;prebuild&quot;: &quot;rimraf dist&quot;,
      &quot;build&quot;: &quot;nest build&quot;,
      &quot;format&quot;: &quot;prettier --write \&quot;src/**/*.ts\&quot; \&quot;test/**/*.ts\&quot;&quot;,
      &quot;start&quot;: &quot;nest start&quot;,
      &quot;start:dev&quot;: &quot;nest start --watch&quot;,
      &quot;start:debug&quot;: &quot;nest start --debug --watch&quot;,
      &quot;start:prod&quot;: &quot;node dist/main&quot;,
      &quot;lint&quot;: &quot;eslint \&quot;{src,apps,libs,test}/**/*.ts\&quot; --fix&quot;,
      &quot;test&quot;: &quot;jest&quot;,
      &quot;test:watch&quot;: &quot;jest --watch&quot;,
      &quot;test:cov&quot;: &quot;jest --coverage&quot;,
      &quot;test:debug&quot;: &quot;node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand&quot;,
      &quot;test:e2e&quot;: &quot;jest --config ./test/jest-e2e.json&quot;
    }
  </code></pre>
  <p>When deploying I see in the logs that it did something like this:</p>
  <pre><code>Jan 23 20:01:14 web: &gt; app@0.0.1 start /var/app/current
  Jan 23 20:01:14 ip-172-31-17-171 web: &gt; sudo npm i -g @nestjs/cli &amp;&amp; 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! app@0.0.1 start: `sudo npm i -g @nestjs/cli &amp;&amp; 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 app@0.0.1 start script.
  </code></pre>
  <p>So I am getting 502 when entering the env url.</p>
  <p>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?</p>
  <p>It is my first time trying to deploy a backend server to eb :)</p>