I'm trying to understand how promises, callbacks etc work in node.js, particularly in the case of accessing the value outside of the function. I've spent time going through the answers here How do I return the response from an asynchronous call? and here call Stripe API with await but every variation I try I always end up with 'subscription' outside the function as undefined.
Thanks
let subscription;
async function getSub(){
subscription = await stripe.subscriptions.retrieve('sub_HurxwcQoCIH7jv');
// code here only executes _after_ the request is done?
return subscription
}
getSub()
console.log("subscription: ", subscription) // subscription undefined??