I have this function:
getSlaves: function() {
fs.readFile('/etc/hosts', function(err, data) {
var array = data.toString().split("\n");
for(i in array) {
if (array[i].indexOf('slave') > -1){
var workerNo = array[i].slice(-1);
var ip = array[i].split(" ");
console.log(ip);
}
}
});
}
At present it writes this to console:
[ '192.168.11.1', 'slave1' ]
[ '192.168.11.2', 'slave2' ]
[ '192.168.11.3', 'slave3' ]
I want this to return so I can use it in another function. I've tried adding return(ip)
and callback(ip)
to the method but that doesn't work.How can I return these values so they can be used by an different function?