Search code examples
node.jsamazon-lightsailforever-monitor

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

Solution

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