How deploy NestJs app in PM2 with nx workspace - AWS ec2

384 Views Asked by At

I am using the NX workspace. In my project have a Nest Js app. I used to deploy this app in AWS EC2. I installed PM2 there.

// pm2.config.js
module.exports = {
  apps: [
    {
      name: 'Backend API',
      script: 'npm',
      args: 'start',
      cwd: 'apps/api/src',
      interpreter: 'ts-node',
      env: {
        PORT: 3000,
        NODE_ENV: 'production',
      },
    },
  ],
};


This strip is in my root directory and I run pm2 start pm2.config.js

Not working. Have any solution for this

1

There are 1 best solutions below

0
Bhanuka Krish On
// pm2.config.js
module.exports = {
  apps: [
    {
      name: 'Backend API',
      script: 'npx',
      args: 'nx run api:serve',
      cwd: 'apps/api',
      interpreter: 'ts-node',
      env: {
        PORT: 3000,
        NODE_ENV: 'production',
      },
    },
  ],
};

I just change this script to this. It's work