1
The problem is with variables why the function async
is running after the variable assignment. what can I do for the function to run and wait for it to finish to take the variable value?
var request = require('request');
function information(callback) {
var options = {
url: "http://someurl.com",
method: "GET",
headers: {
Token: "MV"
}
}
request(options, function (error, response, body) {
if (!error) {
try {
json = JSON.parse(body);
callback(json);
} catch (error) {
error = 'error'
callback(error);
}
}
})
}
var foo;
information(function (bar) {
if (bar) {
console.log(foo);
foo = bar;
console.log(foo);
}
})
console.log(foo);