1

i am creating a windows service that adds some data randomly to a database , so i used node-windows to implement it and when i run the file it creates an executable file and when i run that file i get "cannot start service from the command line or a debugger. a windows service must first be installed" what should i do ??

here is the app.js file code :

var Service = require('node-windows').Service;
var svc = new Service({
    name:'finaltest',
    description: 'The nodejs.org example web server.',
    script: 'testapp.js',

  });

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



  svc.install();

and this is the testapp.js file code :

var test = require('./models/test') ;
test.create({test : Math.random()}).then( () => {
    console.log('hey') ;
})
setInterval(function(){


    test.create({test : Math.random()}).then( () => {
        console.log('hey') ;
    })
}, 60000);
bg1
  • 54
  • 8

1 Answers1

-1

Before a Windows Service can run, it has to be "installed" first using installutil. EG:

C:\installutil -i c:\path\to\project\debug\service.exe

Using net stop [service name] to stop it and net start [service name] to start it up again basically restarting the service.

If so, you should make sure you have done the thing correctly. If tha't not what you want, please be more specific about what you are trying to do and feel free to let me know.

Firstly you should make sure your service code is working fine.

Secondly, if you are win7 or win8 os,

  1. On the Windows Start menu or Start screen, choose Visual Studio, Visual Studio Tools, Developer Command Prompt.
  2. A Visual Studio command prompt appears.
  3. Run InstallUtil.exe from the command prompt with your project's output as a parameter:

    installutil /u "yourproject".exe

Here is my screenshot,

enter image description here

mohammad javad ahmadi
  • 2,031
  • 1
  • 10
  • 27
  • i am getting : “'installutil' is not recognized as an internal or external command ?? – bg1 Jul 03 '19 at 11:45
  • see this link : https://stackoverflow.com/questions/12703645/how-to-resolve-installutil-is-not-recognized-as-an-internal-or-external-comma – mohammad javad ahmadi Jul 03 '19 at 11:50
  • when i run the installutil command i am getting this "No public installer with the RunInstallerAttribute.Yes attribute was found in the C: \ ...\ nodeservicetest service.exe assembly. Removed the InstallState file because no installer is present." but in the end it says that the installation has completted and when i run net start i get access denied . – bg1 Jul 03 '19 at 11:57