Issue with executing npm scripts via pm2 in Windows
Asked Answered
I

1

6

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)
Illeetvilaine answered 16/7, 2018 at 7:38 Comment(2)
We can't help you unless you provide more detail. What do you mean "unable to do it"? What error are you getting?Evalynevan
I have a same issue. Did-you have solve this issue and how ?Polito
S
12

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

Striction answered 19/5, 2019 at 0:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.