Kev
Kev

Reputation: 5442

How can I deploy only one specific nodeJS app to one specific environment with PM2?

I have two nodejs app deployed on Digital Ocean, with PM2, which I am learning. I'd like to know how I could update my apps (services) separately.

At the moment my pm2 config looks like this:

// ecosystem.config.js
module.exports = {
  apps: [
    {
      name: `app1`,
      script: './app1.js',
      // ...
    },
    {
      name: `app2`,
      script: './app2.js',
      // ...
    }
  ],

  deploy: {
    production: {
      key: '',
      user: 'admin',
      host: '',
      ref: '',
      repo: '',
      path: '/home/admin/app/prod',
      'post-deploy': './deploy.sh production'
    },
    development: {
      key: '',
      user: 'admin',
      host: '',
      ref: '',
      repo: '',
      path: '/home/admin/app/development',
      'post-deploy': './deploy.sh development'
    },
  }
}

I can deploy per environment, like pm2 deploy production.
But, can I do something like pm2 deploy development app2 to only update app2?

Upvotes: 0

Views: 1033

Answers (1)

blastz
blastz

Reputation: 365

You have many ways to do that, for me I always create ecosystem file in the client folder and server folder, then create publish ecosystem file in the root folder, like:

  • client
    • ecosystem.config.js
  • server
    • ecosystem.config.js
  • ecosystem.config.js

The root ecosystem file like:

  deploy: {
    frontend: {
      ...other,
      path: '/app/easyv_spaceship',
      'post-deploy': 'cd ./client && npm install && npm run build'
    },
    backend: {
      ...other,
      path: '/app/easyv_spaceship',
      'post-deploy': 'cd ./server && npm install && npm run tsc && pm2 startOrRestart ecosystem.config.js --env production'
    }
  }

hope this can inspire you.

Upvotes: 2

Related Questions