I'm having an issue with the scope of a variable. I need to be able to access "userLocation" outside of "request". The request package can be found at https://github.com/request/request Here's my code below:
var request = require('request');
var userLocation = "";
request('http://ipinfo.io', function(error, res, body) {
var ipDetails = JSON.parse(body);
userLocation = ipDetails.loc;
});
console.log(userLocation);
When I try to output the "userLocation" variable, it prints an empty string instead of the details from the request package.