0

我正在创建一个 Windows 服务,该服务将一些数据随机添加到数据库中,所以我使用 node-windows 来实现它,当我运行该文件时,它会创建一个可执行文件,当我运行该文件时,我得到“无法从命令启动服务行或调试器。必须首先安装 Windows 服务“我该怎么办??

这是 app.js 文件代码:

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();

这是 testapp.js 文件代码:

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);
4

1 回答 1

0

在 Windows 服务可以运行之前,它必须首先使用 installutil 进行“安装”。例如:

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

使用 net stop [service name] 停止它并使用 net start [service name] 再次启动它,基本上重新启动服务。

如果是这样,你应该确保你已经正确地完成了这件事。如果这不是您想要的,请更具体地说明您要做什么,并随时让我知道。

首先,您应该确保您的服务代码工作正常。

其次,如果你是win7或win8操作系统,

  1. 在 Windows 开始菜单或开始屏幕上,选择 Visual Studio、Visual Studio 工具、开发人员命令提示符。
  2. 出现 Visual Studio 命令提示符。
  3. 从命令提示符运行 InstallUtil.exe,并将项目的输出作为参数:

    installutil /u“你的项目”.exe

这是我的截图,

在此处输入图像描述

于 2019-07-03T11:24:36.690 回答