0

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.

Colin
  • 1,112
  • 1
  • 16
  • 27
Rachel
  • 173
  • 4
  • 12
  • Put your `res.send` function inside `flutterwave.BIN.check` like this `flutterwave.BIN.check(cardnumber, function(req,res){ country = country + res.body.data.country; console.log(country); res.send(JSON.stringify({status: "200","country":country})); });` – CIPHER007 Aug 03 '17 at 09:57
  • @CIPHER007:- Tried that but doesnt work. Error - res.send() is not a function. – Rachel Aug 03 '17 at 10:00
  • you have to change the name of one `res` because you have one more `res` in the function `flutterwave.BIN.check(cardnumber, function(req,res)`. – CIPHER007 Aug 03 '17 at 10:03

0 Answers0