In async world you can't return values. Whatever needs to be done when the value is ready should be executed inside the callback. Another alternative is using promises. You'll need the es6-promise package:
var Promise = require('es6-promise').Promise;
var asyncJobInfo = function(jobID) {
var oozie = oozieNode.createClient({config: config});
var command = 'job/' + jobID + '?show=info';
console.log("running oozie command: " + command);
// Creates a new promise that wraps
// your async code, and exposes two callbacks:
// success, and fail.
return new Promise(function(success, fail) {
oozie.get(command, function(error, response) {
if (error) {
fail(error);
} else {
success(response);
}
});
});
};
Now you can use the promise and pass the callbacks that will run once it is resolved:
exports.getJobInfoByID = function(req, res) {
asyncJobInfo(req.params.id).then(function(data) {
res.send(data)
}).catch(function(error) {
console.error(error);
});
};
The above can be shortened:
exports.getJobInfoByID = function(req, res) {
asyncJobInfo(req.params.id)
.then(res.send.bind(res))
.catch(console.error);
};