2

我想作为服务运行的脚本需要“启动”作为参数。

我如何设置参数node-windows

这里是项目页面中的设置 js 脚本:

var Service = require('node-windows').Service;

// Create a new service object
var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\wiki.js',
  nodeOptions: [
    '--harmony',
    '--max_old_space_size=4096'
  ]
});

// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
  svc.start();
});

svc.install();

将脚本值设置为“wiki start”会导致错误,因为模块将其视为文件。这里的日志:

Starting C:\Program Files\nodejs\node.exe  --harmony --max_old_space_size=4096 C:\Users\<me>\AppData\Roaming\npm\node_modules\node-windows\lib\wrapper.js --file ..\wiki.js --log "wiki.js wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst undefined "-- start"

我也尝试发送nodeOptions,将“--start”添加到数组中,但模块将其作为字符串添加到命令行,即“--start”。

4

1 回答 1

0

这就是scriptOptions参数的用途。它是在node-windows@0.1.11中引入的

var svc = new Service({
  name:'Hello World',
  description: 'The nodejs.org example web server.',
  script: 'C:\\path\\to\\wiki.js',
  scriptOptions: 'start'
});
于 2020-05-27T22:24:17.123 回答