我有这个节点 cli 脚本
#!/usr/bin/env node
const path = require('path');
const forever = require('forever-monitor');
const script = path.format({dir: __dirname, base: 'pager.js'});
const chalk = require('chalk');
const commander = require('commander');
commander.version('1.0.0')
.option('-m, --message', 'set awesome message')
.parse();
const args = commander.opts();
const header = `
+---------------------+
| Awesome v1.0 |
+---------------------+
`;
const child = new (forever.Monitor)(script, {
max: 2,
silent: false,
args: args
});
child.start();
child.on('start', (process) => {
console.log(chalk.magenta.bold(header));
});
child.on('restart', () => {
console.log(`Forever restarting script for ${child.times} time`);
});
child.on('exit:code', (code) => {
console.log(`Forever detected script exited with code ${code}`);
});
我想集成指挥官,让用户能够传递将被解析的参数,然后传递给正在运行的子进程,直到终端在永远监控npm 包的帮助下关闭。目前我尝试在子进程中使用指挥官但没有成功,它将被忽略。然后我将它移到我的index.js
代码中,但我不知道如何将参数传递给子进程。目前,如果我将解析的参数传递给args
永远监视器的选项,我会收到此错误
host:awesome dev$ node . -m 'Hello!'
/Users/dev/Desktop/awesome/node_modules/forever-monitor/lib/forever-monitor/monitor.js:130
this.args.unshift(script);
^
TypeError: this.args.unshift is not a function
at new exports.Monitor (/Users/dev/Desktop/awesome/node_modules/forever-monitor/lib/forever-monitor/monitor.js:130:15)
at Object.<anonymous> (/Users/dev/Desktop/awesome/index.js:20:15)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
谁能给我一些帮助?