栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

引导时自动启动node.js服务器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

引导时自动启动node.js服务器

根本不需要在node.js中进行配置,这完全是操作系统的职责(在您的情况下为Windows)。实现此目的的最可靠方法是通过Windows服务。

有一个 超级简单的 模块,它可以将节点脚本安装为Windows服务,称为 节点窗口
(npm,github,documentation)。我以前用过并且像魅力一样工作。

var Service = require('node-windows').Service;// Create a new service objectvar 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();

ps

我发现它非常有用,以至于在它周围构建了一个更易于使用的包装器(npm,github)。

安装它:

npm install -g qckwinsvc

安装服务:

> qckwinsvcprompt: Service name: [name for your service]prompt: Service description: [description for it]prompt: Node script path: [path of your node script]Service installed

卸载服务:

> qckwinsvc --uninstallprompt: Service name: [name of your service]prompt: Node script path: [path of your node script]Service stoppedService uninstalled


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/436512.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号