I am a bit confused about this error that I keep getting. So, I am calling an api within a post request and then I am extracting a specific field called country. Now, I wanted to return the country value inside my res.send
function but for some reason, it keeps returning the initial value of country that I initialized. Even though the country variable value changes but it keeps sending the intial value. What could I be doing wrong?
app.post('/checkcardbin',function(req,res) {
var cardnumber = req.body.cardnumber;
var country = "";
flutterwave.BIN.check(cardnumber, function(req,res){
country = country + res.body.data.country;
console.log(country);
});
res.send(JSON.stringify({status: "200","country":country}));
});
Instead of sending the new value of the country, it keeps sending me the default value that I initialized.