【问题标题】:starting, stopping and restarting windows services using node js使用节点 js 启动、停止和重新启动 Windows 服务
【发布时间】:2018-08-27 09:07:53
【问题描述】:

谁能解释我如何使用节点程序启动或停止 Windows 服务?不是在 Windows 上运行的 NodeJS 服务,而是特别是 Windows 服务本身,而且也使用 NODEJS。有很多关于如何杀死或启动 NodeJS 服务的文章,但不是我在这里需要的。在以下链接中有一篇关于 StackOverflow 的文章:

Node js start and stop windows services

但我要么做得不对,因为我没有按照它应该的方式理解它,要么它没有做我需要它做的事情。请帮帮我。不知道为什么,网上几乎没有这方面的文章。

【问题讨论】:

    标签: node.js windows service


    【解决方案1】:

    使用os-services模块

    npm install os-service
    It is loaded using the require() function:
    
    var service = require ("os-service");
    A program can then be added, removed and run as a service:
    
    service.add ("my-service");
    
    service.remove ("my-service");
    
    service.run (function () {
        // Stop request received (i.e. a kill signal on Linux or from the
        // Service Control Manager on Windows), so let's stop!
        service.stop ();
    });
    

    【讨论】:

    • 没有 Waqar.. 没用。无论如何,感谢您的帮助。
    • 您遇到什么错误?请发布错误,以便我们进一步解决。
    • 当 OP 说它不能解决问题时,为什么这是一个公认的答案?好不好用?
    【解决方案2】:

    使用 bat 文件来停止和启动节点服务器或用户 nodemon 包。 并使用windows任务调度器

    @echo off
    cd "D:\sam\Projects\NodeSchedule // path of node project i.e. index.js
    taskkill /IM node.exe -F
    start /min cmd /C "node index.js"
    goto :EOF
    

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 2013-01-29
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多