how can I get data from a variable outside of the function? Below is the code, in the comments I put a description of what I mean.
var url = 'http://localhost/cron/temp.php';
request.get({
url: url,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, data) => {
if (err) {
console.log('Error:', err);
} else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
} else {
// data is already parsed as JSON:
console.log(data);
var temp = data; // This var
}
});
console.log(temp); // How to get here?