Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
--使用json配置模式时PM2中的节点参数_Json_Node.js_Pm2 - Fatal编程技术网

--使用json配置模式时PM2中的节点参数

--使用json配置模式时PM2中的节点参数,json,node.js,pm2,Json,Node.js,Pm2,我有一个问题,那就是如何在使用json配置模式时在PM2中传递“-node args”参数,如下所示: pm2启动--node args=“--debug=5858”myPm2Config.json 嗯,我知道我可以将参数写入myPm2Config.json文件,但我不想这样做,因为我想为启动应用程序创建两个启动命令,分别为“debug”和“production”模式,例如“pm2_run”和“pm2_debug”,以及带有--node args参数和“pm2_run”的“pm2_debug”命

我有一个问题,那就是如何在使用json配置模式时在PM2中传递“-node args”参数,如下所示:

pm2启动--node args=“--debug=5858”myPm2Config.json


嗯,我知道我可以将参数写入myPm2Config.json文件,但我不想这样做,因为我想为启动应用程序创建两个启动命令,分别为“debug”和“production”模式,例如“pm2_run”和“pm2_debug”,以及带有--node args参数和“pm2_run”的“pm2_debug”命令,我不想创建两个“myPm2Config.json”文件,因为这意味着如果需要更改某些内容,我将需要更改两个json配置文件,那么,有没有简单的方法可以做到这一点?谢谢大家!

我找到了解决方案!那就是使用js配置而不是json配置

首先,我创建了一个pm2.config.js文件。(标记:文件名必须以.config.js结尾)

//[pm2.config.js]

let config = {
  apps : [{
    name        : "node_shells",
    script      : "./bin/www",
    log_date_format  : "YYYY-MM-DD HH:mm:SS",
    log_file   : "logs/pm2.log",
    error_file : "logs/pm2-err.log",
    out_file   : "logs/pm2-out.log",
    pid_file   : "logs/pm2.pid",
    watch      :  true,
    ignore_watch : ["logs/*", "node_modules/*", "uploads/*"]
  }]
}

let debug_mode = false;
for(let arg of process.argv) {
  if(arg == '-debug') {
    debug_mode = true;
    break;
  }
}

if(debug_mode) {
  console.log('== launching in debug mode ==');
  config.apps[0].node_args = "--debug=5858";
}
else {
  console.log('== launching in production mode ==');
  config.apps[0].node_args = " ";   //*require! or it will always uses latest debug options
}

module.exports = config;
然后,创建两个启动文件:“pm2_运行”和“pm2_调试”



现在,很容易切换调试模式或生产模式!

我找到了解决方案!那就是使用js配置而不是json配置

首先,我创建了一个pm2.config.js文件。(标记:文件名必须以.config.js结尾)

//[pm2.config.js]

let config = {
  apps : [{
    name        : "node_shells",
    script      : "./bin/www",
    log_date_format  : "YYYY-MM-DD HH:mm:SS",
    log_file   : "logs/pm2.log",
    error_file : "logs/pm2-err.log",
    out_file   : "logs/pm2-out.log",
    pid_file   : "logs/pm2.pid",
    watch      :  true,
    ignore_watch : ["logs/*", "node_modules/*", "uploads/*"]
  }]
}

let debug_mode = false;
for(let arg of process.argv) {
  if(arg == '-debug') {
    debug_mode = true;
    break;
  }
}

if(debug_mode) {
  console.log('== launching in debug mode ==');
  config.apps[0].node_args = "--debug=5858";
}
else {
  console.log('== launching in production mode ==');
  config.apps[0].node_args = " ";   //*require! or it will always uses latest debug options
}

module.exports = config;
然后,创建两个启动文件:“pm2_运行”和“pm2_调试”


现在,很容易切换调试模式或生产模式

#[pm2_debug]
pm2 start pm2.config.js -- -debug