Question

Cannot use forever.list method in node.js code ...

var forever;

forever = require('forever');

forever.startServer();

forever.list("", function(result) {
  return console.log(result);
});

... prints null in console.

Although in terminal when run forever list, I see running precesses.

❯ forever list
info:    Forever processes running
data:        uid  command             script forever pid   logfile                       uptime       
data:    [0] 1QNd /usr/local/bin/node app.js 29937   29979 /Users/user/.forever/1QNd.log 0:0:26:23.55

And I want to get the same date inside node.js script.

Maybe I use list with invalid arguments. First argument format - I pass empty string, because don't know what to pass.

Was it helpful?

Solution

forever.list is a cli command, so you can not use directly in your code. If you are using forever programatically you should install forever-monitor.

So maybe you can call the cli command, e.g.:

var exec = require('child_process').exec;

function execute(command, callback) {
    exec(command, function(err, stdout, stderr) {
    callback(stdout);
  })
};

execute('forever list', function(ret) {
  console.log(ret);
});

out:

info:    Forever processes running
data:        uid  command       script                                            forever pid   logfile                        uptime      
data:    [0] OmsO /usr/bin/node /home/atupal/Dropbox/src/github/nodeblog/server.js 13171   13173 /home/atupal/.forever/OmsO.log 0:0:0:4.164 

OTHER TIPS

This answer in forever 0.15.2

Please see forever list command code in cli.js https://github.com/foreverjs/forever/blob/master/lib/forever/cli.js#L428

//
// ### function list ()
// Lists all currently running forever processes.
//
app.cmd('list', cli.list = function () {
  forever.list(true, function (err, processes) {
    if (processes) {
      forever.log.info('Forever processes running');
      processes.split('\n').forEach(function (line) {
        forever.log.data(line);
      });
    }
    else {
      forever.log.info('No forever processes running');
    }
  });
});

Expect your code.

var forever = require('forever');

// If set 'true' to @format, return 'processes' is formatted strings.
forever.list(true, function (err, processes) {
  console.log(err);
  console.log(processes);
});

// If set 'false' to @format, return 'processes' is object.
forever.list(false, function (err, processes) {
  console.log(err);
  console.dir(processes);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top