I am not an expert in javascript or node so this is probably something simple. I have tried to search but I cannot find an answer.
I have
request({url:url}, function (error, response, body) {
if (!error && response.statusCode == 200) {
a = JSON.parse(body);
b=(a.result[0].approval);
} else{console.log(error)}
})
How do I return the b value. I tried wrapping the entire thing in a function and returning b that way but that did not work.
function getVal(url){
var a
request({url:url}, function (error, response, body) {
if (!error && response.statusCode == 200) {
a = JSON.parse(body);
b = (a.result[0].approval);
console.log(b)
} else{console.log(error)}
return a
})
return a;
}
b = getVal(url)
My logic was calling function should have the scope of what it calls. I have tried various ways of returning the value and nothing works. I know the answer is easy but I have no more things to try.