Promise method of Node JS and how it simplifies the callback problem
Hi guys,Today we will see how we can avoid callback problems by Advanced method of node Provided by Node version 6.5.0 (or further version). Its Promise method.You don't need to include any library for that.Below is the example. function asyncJobFunction() { var url="mydomain.com"; return new Promise(function(resolve,reject){ //Write here your Async Code call.Get(url,function(err,data) { if(err) { reject(err); ///Reject the Promise by calling the reject method. } else { console.log("Success"); resolve(data); ///Resolve the Promise by calling the resolve method. } }) }) } above we have written one function asyncJobFunction which returns the promise object.so we have to catch the result either resolve or reject. lets see how we can catch that. var promiseData=asyncJobFunction(); promiseData.then(function(result){ console.log("Success"); console.log(result); /...