in an express router .post which is async, I have this line:
var recaptcha = await tokenValidate(req);
tokenValidate is below:
async function tokenValidate(req) {
// some code to generate a URL with a private key, public key, etc.
return await tokenrequest(url);
}
Then tokenrequest is below: (note request is the npm request library)
async function tokenrequest(url) {
request(url, function(err, response, body){
//the body is the data that contains success message
body = JSON.parse(body);
//check if the validation failed
if(body.success !== undefined && !body.success){
return false;
}
//if passed response success message to client
return true;
})
}
Issue is the nested async functions. The initial recaptcha variable returns undefined since 'request' doesn't resolve, even though I'm using await. How can I get recaptcha to wait for tokenValidate which in turn has to wait for tokenrequest?
Thank you.