coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.78k stars 357 forks source link

[question] how to use node-windows to run the script in package.json? #301

Closed radiorz closed 2 years ago

radiorz commented 2 years ago

[question] how to use node-windows to run the script in package.json?

radiorz commented 2 years ago

such as

"scripts": {
    "test": "node start.js -c config.js -e",
}
radiorz commented 2 years ago

I try to install service like this but it cannot be started.

let path = require('path');
let { Service } = require('node-windows');

// Create a new service object
let svc = new Service({
    name: 'proxy Server',
    description: 'proxy server to device and uiptalk server',
    script: path.resolve('./start.js'), 
    nodeOptions: ['-c', path.resolve('./config.js'),'-e'],
});

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

svc.install();
radiorz commented 2 years ago
let path = require('path');
let { Service } = require('node-windows');

// Create a new service object
let svc = new Service({
    name: 'proxy Server',
    description: 'proxy server to device and uiptalk server',
    script: path.resolve('./start.js'), 
    scriptOptions: `-c ${path.resolve('./config.js')} -e`,
});

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

svc.install();

It works!~!!