I want a value from child function to the parent function in a Node.js and use that value in another file. Being asynchronous flow the output of d.promise is pending.
How can I get the value of d.promise as fulfilled with the data passed in the arangoFunction.js file in the queryCheck variable in the site.js file?
Database used : ArangoDB
site.js snippet
var arangoFunc = require('./arangoFunction'), queryCheck;
queryCheck = arangoFunc.saveData(data, roleCollection, res);
console.log(queryCheck);
arangoFunction.js snippet
var q = require('q');
var d = q.defer();
exports.saveData = function(data, collectionName, res){
var collectionData = db.collection(collectionName);
collectionData.save(data, function(e, o){
if(e) {
console.error(e);
res.status(e.response.statusCode).send(e.response.statusMessage);
d.reject(false);
}
else {
res.send(data);
d.resolve(data);
}
});
return d.promise;
}
Output of site.js snippet
{ state: 'pending' }