Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with executing npm scripts via pm2 in Windows

I am trying to run npm custom scripts via pm2 using ecosystem.json as,

{
    "apps": [{
        "name": "Service",
        "script": "npm",
        "args": "run command"
    }]
}

Unfortunately I am unable to do it. Can anyone help me to get through this? I am getting as shown below,

C:\PROGRAM FILES\NODEJS\NPM.CMD:1
0|Service | (function (exports, require, module, __filename, __dirname) { :: 
Created by npm, please don't edit manually.
0|Service |                                                               ^
0|Service | SyntaxError: Unexpected token :
0|Service |     at createScript (vm.js:56:10)
0|Service |     at Object.runInThisContext (vm.js:97:10)
0|Service |     at Module._compile (module.js:542:28)
0|Service |     at Object.Module._extensions..js (module.js:579:10)
0|Service |     at Module.load (module.js:487:32)
0|Service |     at tryModuleLoad (module.js:446:12)
0|Service |     at Function.Module._load (module.js:438:3)
0|Service |     at Object.<anonymous> 
(C:\Users\AD001\AppData\Roaming\npm\node_modules\pm2\
lib\ProcessContainerFork.js:53:21)
0|Service |     at Module._compile (module.js:570:32)
0|Service |     at Object.Module._extensions..js (module.js:579:10)
like image 944
Praveenkumar Kalidass Avatar asked Jul 16 '18 07:07

Praveenkumar Kalidass


1 Answers

this is a reported issue in pm2. you can work around by doing

//startscript.js
var exec = require('child_process').exec;
exec('npm start', {windowsHide: true});

then pm2 start startscript.js

like image 120
Ron87k Avatar answered Oct 01 '22 16:10

Ron87k