Service not getting installed using node-windows

275 Views Asked by At

I tried using node-windows to create a service > "daemon" folder was getting created but service was not getting installed. Following is the code :

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

var svc = new Service({
  name: 'MyService',
  description: 'Trial service',
  script:'app.js',
  abortOnError:false
});

console.log("....", svc);

svc.on('install', function() {
  console.log('installed');
  return svc.start();
});

svc.on('error', function() {
  return console.log('error');
});

svc.on('start',function(){
  console.log(svc.name+' started!');
});

svc.on('alreadyinstalled', function() {
  return console.log('alreadyinstalled');
});

svc.install();
1

There are 1 best solutions below

0
On

Here is the script I use and it works.

var Service = require('node-windows').Service;
 
// Create a new service object
var svc = new Service({
name:'AM-API-MDD port 3050',
description: 'API Server for MDD db (port:3050)',
script: 'C:\\Sites\\AM-API-MDD\\dist\\main.js',
// execPath: 'C:\\Program Files\\nodejs14\\node.exe'
});

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