在开发服务器上使用永远监控器运行NodeJS进程

时间:2018-11-09 11:05:41

标签: node.js amazon-lightsail forever-monitor

我正在尝试连续运行我的expressJS应用 在使用永久监控的服务器上。 我没有收到任何错误,但是我的应用无法按预期运行, 3重新启动后,该过程退出。 我可以在此处省略最大值还是连续运行该应用程序会缺少什么?

信息:我正在将其部署到AWS Lightail服务器。

我实现的代码来自永远监控的git repo。

var forever = require('forever-monitor');

var child = new (forever.Monitor)('app.js', {
max: 3,
silent: true,
args: []
});

child.on('exit', function () {
console.log('program has exited after 3 restarts');
});

child.start();  

1 个答案:

答案 0 :(得分:0)

我必须同时安装永久和永久监视依赖项才能使应用程序连续运行。 关闭CLI会话后,该应用程序现在将按预期运行。

var forever = require('forever-monitor');

var child = new (forever.Monitor)('app.js', {
max:3,
silent: true,
sourceDir: '/app.js',
watch:true,
args: []
});

child.on('watch:restart', function(info) {
console.error('Restaring script because ' + info.file + ' changed');
});

child.on('restart', function() {
console.error('Forever restarting script for ' + child.times + ' time');
});

child.on('exit:code', function(code) {
console.error('Forever detected script exited with code ' + code);
});

child.start();