Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.49k stars 2.62k forks source link

Example: npm run start in win11, and prevent cmd.exe window popup #5608

Open linonetwo opened 1 year ago

linonetwo commented 1 year ago

https://github.com/Unitech/pm2/issues/3657#issuecomment-1552997822

This works for npm run start in win11, and will prevent cmd.exe window popup:

module.exports = {
  apps: [
    {
      name: 'qq-bot',
      // script: 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
      // instances: 1,
      // exec_mode: 'cluster',
      script: 'npm',
      args: 'run start',
      cwd: 'D:/repo/qq-bot',
      interpreter: process.platform === 'win32' && 'C:\\Windows\\System32\\cmd.exe',
    },
  ],
};

I tried C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js with fork mode and it will popup cmd.exe.

I tried cluster mode, but it won't execute things in npm script, if that script point to a ps1 or bat shell file in node_modules/.bin

But with interpreter cmd.exe + script: 'npm' this works well.

linonetwo commented 1 year ago

Above IS NOT WORKING.

But after use https://github.com/jessety/pm2-installer to start pm2 on background on win11 startup, this will not pop up cmd.exe window.

You need to run pm2 save to save current tasks to the startup list, then on next startup, they will run on the backgound, and no popup.

hp8wvvvgnj6asjm7 commented 1 year ago

I have the same problem. Running the npm cmd causes token error. Targeting npm-cli.js opens up a cmd.

https://github.com/Unitech/pm2/issues/5616