I am trying to build a backend script to call recurly api to load data and store it. I declare the function and assigned to getAccountInfo, after that I tried to call the function, but console says getAccountInfo is not a funtion.. And also console.log(accountInfo) display undefined. But I can watch it inside the function declaration.
The api parameter required the callback function, that is why it looks like this.
var accountInfo = {};
let getAccountInfo = recurly.accounts.list(function (errResponse, response) {
if (errResponse) {
reject(errResponse);
}
if (response) {
accountInfo = response.data.accounts.account;
resolve(response);
}
}, );
getAccountInfo();
console.log(accountInfo);
I expect that I can run the function and get the accountInfo. I am new to javascript and Node js, is that any concept that I misunderstood? Thank you very much for the help.