0

I used to start a nodejs script with this command

node cli/myscript.js -c configs/some-config.json

I tried to start the same script using pm2. I found here a post handling the same theme.

I tried this :

pm2 start cli/myscript.js --node-args="-c configs/some-config.json"

I get a syntax error on the config file which I don't get when I don't use pm2.

SyntaxError: Unexpected token :
0|myscript  |     at checkScriptSyntax 

I also tried this and get the same error:

pm2 start cli/myscript.js -- -c configs/some-config.json

It seems like that pm2 tries to execute the config as a js file.. because the config file is a valid json.

dens
  • 13
  • 2

1 Answers1

0

You can pass the file name in the same-config.json.

  {
  "apps" : [{
    "name"        : "myscript",
    "script"      : "cli/myscript.js",
    "watch"       : true,
    "env": {
      "NODE_ENV": "development"
    }
  }]
}

Then you can run the node server by following command -

pm2 start same-config.json

For more details please refer PM2 docs

Siddharth Yadav
  • 383
  • 2
  • 9