全局安装
npm install -g node-windows
或在项目中安装
npm install node-windows --save
写启动脚本
nodeWindow.js
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'Hello World',//服务名
description: 'The nodejs.org example web server.', //服务描述
script: 'C:\\path\\to\\helloworld.js'//要启动的文件路径
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
根据项目命令启动nodeWindow.js脚本,会在服务里面名为hello world 的服务

本文介绍如何使用node-windows全局安装Node.js服务并配置启动脚本。通过npm命令完成服务安装,随后设置服务名称、描述及指定启动文件路径。

被折叠的 条评论
为什么被折叠?



