我的安装服务脚本如下:
install_windows_service.js
require("dotenv").config();
var Service = require("node-windows").Service;
// Create a new service object
var svc = new Service({
name: "STUtility",
description: "The web app with STUtility tools.",
script: process.env.WORKING_DIRECTORY + "index.js",
nodeOptions: ["--harmony", "--max_old_space_size=4096"],
workingDirectory: process.env.WORKING_DIRECTORY,
allowServiceLogon: true,
env: {
name: "NODE_ENV",
value: "production",
},
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on("install", function () {
svc.start();
console.log("install complete.");
console.log("The service exists: ", svc.exists);
});
// Just in case this file is run twice.
svc.on("alreadyinstalled", function () {
console.log("This service is already installed.");
});
// Listen for the "start" event and let us know when the
// process has actually started working.
svc.on("start", function () {
console.log(svc.name + " started!.");
});
svc.on("error", function () {
console.log("Something went wrong.");
});
svc.on("invalidinstallation ", function () {
console.log(" This service is detected but missing require files");
});
svc.install();
在终端我运行命令:
节点 .\install_windows_service.js
终端展示:
安装完成。服务存在:true
但我无法在 Windows 服务上找到此服务。