I'm new to Node.js and I'm experimenting with it.
Since values from one promise are not available globally I'm trying a way to assign value to a variable that can be accessed anywhere down the chain.
What I found is the first block of code always ends in catch and second block works OK the only difference being assignment of value.
Can someone help me with this in doing it right way.
var test = (req,callBack)=>{
var value;
return querydb.checkstatus(req).then((result)=>{
value = 1;
return(result);
}).then((result)=>{
if(result!=null){
callBack(null, value);
}
}).catch((errorMessage)=>{
callBack({Msg:"From Catch"},null);
})
};
var test = (req,callBack)=>{
var value;
querydb.checkstatus(req).then((result)=>{
return(result);
}).then((result)=>{
if(result!=null){
callBack(null, "from then");
}
}).catch((errorMessage)=>{
callBack({Msg:"From Catch"},null);
})
};