iMyke
iMyke

Reputation: 29

Custom npm script in ecosystem.config.js

To start a custom npm script start with pm2 as a one-time process, I'd run pm2 start npm -- start, and to move this into the ecosystem.config.js file, my app would be configured as

...
script: 'npm',
args: 'start',
...

But things fall apart when instead of start, I need to run the dev script, like you would in npm run dev. I've tried

...
script: 'npm run dev',
...
...
script: 'npm',
args: 'run dev',
...

and

...
script: 'npm',
args: 'dev',
...

with no luck so far. Could I be missing something, or is there an entirely different approach?

Upvotes: 1

Views: 3629

Answers (3)

Super Hero
Super Hero

Reputation: 11

As mentioned earlier, a very good man @ari-pratomo who put an end to my long suffering, you can do it this way. Take a look at __dirname. If you run your ecosystem.config.js from cli already being at the root of the project - it could help you.

module.exports = {
  apps : [
    {
      name: 'my-app-name',
      script: 'npm',
      cwd: __dirname,
      args: 'run start',
    },
  ],
};

Upvotes: 0

Ari Pratomo
Ari Pratomo

Reputation: 1243

you missing cwd field, the directory from which your app will be launched

...
name: 'app',
script: 'npm',
cwd: '/var/www/html/app',
args: 'run develop',
...

Upvotes: 0

Pravin Jadav
Pravin Jadav

Reputation: 1

I'm using reactJs + nextJs and I'm also facing the same issue with ecosystem.config.js configuration in PM2, but you can use the following command it's working for me.

pm2 start "npm run dev" --name YOUR_APP_NAME

Upvotes: 0

Related Questions