coreybutler / node-windows

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

npm run SCRIPT #285

Closed puentesdiaz closed 3 years ago

puentesdiaz commented 3 years ago

i have a package.json like...

`"scripts": {

"startServers": "concurrently --kill-others \"npm run proxy\" \"npm run dev-server\" ",  

"proxy": "node ./api-server.js",

"dev-server": "webpack-dev-server --mode development" 

},`

i usually execute with : npm run startServers

how can i user node-windows for the same?

coreybutler commented 3 years ago

That's not really what this library does. You're attempting to create multiple processes and use a third party runner (webpack dev server).

What you could do is this:

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

// Create a new service object
var svc = new Service({
  name:'My API Server',
  description: 'My backend',
  script: 'C:\\path\\to\\api-server.js',
  //, workingDirectory: '...'
  //, allowServiceLogon: true
});

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

svc.install();

You could also run the dev server as its own background service. I don't use webpack, so I'm not sure what you'd need to do with that.

One thing I'd like to point out is this library is designed for creating production background services.