简体   繁体   中英

running a NodeJS process with forever-monitor on development server

I am attempting to run my expressJS app continuously on a server using forever-monitor. I don't get any errors however my app does not keep running as expected, the process exits after 3 restarts. Can I omit the max value here or what am I missing to run the app continuously?

Info: I am deploying it to a AWS lightsail server.

the code I have implemented comes from the forever-monitor 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();  

I had to install both forever and forever-monitor dependencies to get the app running continuously. The application runs as expected now after closing the CLI session.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM