Maxim Yefremov Maxim Yefremov - 5 months ago 21
Node.js Question

forever.list returns null in node.js code

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.

Answer

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 
Comments