I'm quite new to node and am trying to create something that gets some server info. But here's my problem. I setup a config object (this will, in time, become updated dynamically by events that occur) and then later in, in a function, I try and access a value in this object. (See code below)
So First, I setup my vars:
var util = require('util'),
child = require('child_process'),
config = {};
which works okay. Then I load my config:
function loadConfig( )
{
// Add some code for auto-loading of args
config = {
"daemons": [
["Apache", "apache2"],
["MySQL", "mysqld"],
["SSH", "sshd"]
]
};
}
and init that calling the function
loadConfig();
After that, I run my check on daemons.
function getDaemonStatus( )
{
for(var i=0; i<config.daemons.length; i++)
{
child.exec( 'ps ax -o \'%c %P\' | awk \'{if (($2 == 1) && ($1 == "\'' +
config.daemons[i][1] + '\'")) print $0}\'',
function( error, stdout, stderr )
{
console.log(config.daemons[i]);
});
}
}
The response I get is:
undefined
undefined
undefined
I don't really want to use a GLOBAL variable, so can you guys think of another way to solve my problem?
Thanks! =]