使用节点js启动,停止和重新启动Windows服务

时间:2018-08-27 09:07:53

标签: node.js windows service

有人可以解释如何使用节点程序启动或停止Windows服务吗?不是在Windows上运行的NodeJS服务,而是Windows服务本身,以及使用NODEJS的服务。关于如何终止或启动NodeJS服务的文章很多,但这里没有我需要的文章。尽管在以下链接中有关于StackOverflow的文章:

Node js start and stop windows services

但是我做错了,因为我没有以应有的方式理解它,或者它没有做我需要做的事情。请帮帮我。不知道为什么,但是几乎没有关于此的在线文章。

2 个答案:

答案 0 :(得分: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 ();
});

答案 1 :(得分:0)

使用bat文件停止和启动节点服务器或用户nodemon软件包。 并使用Windows Task Scheduler

@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
相关问题