[英]Could not correctly pass argument to nodejs using pm2
I used to start a nodejs script with this command 我曾经用这个命令启动一个nodejs脚本
node cli/myscript.js -c configs/some-config.json
I tried to start the same script using pm2. 我尝试使用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. 我在配置文件上遇到语法错误,当我不使用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. 似乎pm2尝试将配置作为js文件执行..因为配置文件是有效的json。
You can pass the file name in the same-config.json. 您可以在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.