ape_face
ape_face

Reputation: 101

How to run multiple pm2 instances each with different cmd args?

I have a whole bunch of files to parse and transform and I've created a nodejs app for this where I supply stuff like source and target dir as cmd args when I run the app. Now I would like to start a whole bunch of these processes each with different cmd args. With npm I have to do this manually. Can I do this programmatically with pm2? Can I say to pm2 run 10 instances of my app, each instance takes different cmd args?

Upvotes: 3

Views: 3194

Answers (1)

madflow
madflow

Reputation: 8490

There is the concept of an ecosystem file.

A minimal example would be:

// worker.js
setInterval(function() {
  console.log(process.argv);
}, 1000);
// ecosystem.config.js
module.exports = {
  apps: [
    {
      name: 'Worker 1',
      script: 'worker.js',
      args: 'one two'
    },
    {
      name: 'Worker 2',
      script: 'worker.js',
      args: 'three four'
    }
  ]
};

In the same directory simply execute: pm2 start

Upvotes: 4

Related Questions