托管nodejs作为Windows服务

时间:2016-04-29 13:08:08

标签: node.js amazon-web-services iis

enter image description here我使用http://nssm.cc/在Windows上托管我的nodejs应用程序作为Windows服务。

但是,当应用程序崩溃时,它不会自动重启。

我相信Windows不会收到有关崩溃的通知。

此外,我无法查看我在应用程序控制台中编写的日志以进行调试。

任何人都可以请求帮助在Windows上作为服务托管nodejs并检查故障日志的最佳方法吗? IISNode也是一种更好的方法吗?

2 个答案:

答案 0 :(得分:0)

我建议使用PM2模块,该模块具有Windows startupservice支持,logmonitoring管理。

答案 1 :(得分:0)

我喜欢Coreynode-windows所做的事情。他在this answer中表明,我正在复制他的步骤:

enter image description here

  

它还内置了系统日志记录。

enter image description here

  

有一个API可以从代码创建脚本,即

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();

它甚至可以重启服务并增加服务的重启时间。

相关问题