How Can I run PM2 with Angular-Cli? - Angular2

But, if you need ng serve for dev in preprod env, you can create a start.sh at root of your project

#!/bin/bash
ng serve --host xxx.xxx.xxx.xxx --port xxxx

And use pm2 like that :

pm2 start start.sh --name my-pretty-dev-app-run-on-preprod

;)


This command would work as expected:

after I run

ng build --prod

then run the following command in the dist/ folder

pm2 start /usr/bin/http-server -- -p 8080 -d false

Update

I have found a better solution: which ng then it will print /usr/bin/ng then type this

pm2 start /usr/bin/ng -- serve --prod


With PM2 recent version

pm2 ecosystem

than update

ecosystem.config.js as follows

module.exports = {
  apps : [{
    name: 'demoapp',
    script: 'node_modules/@angular/cli/bin/ng',
    args: 'serve --host [yourip] --disable-host-check',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }],

  deploy : {
  }
};

finally

pm2 start & pm2 save