I have a simple http.get request to external api. How can I access id and name variables from another function? Thanks!
app.use(function *(next){
var name = '';
var id = '';
var options = {
host: 'www.website.com',
path: '/json/somedata',
metohd: 'GET'
};
http.get(options, function(res) {
var body = '';
res.on('data', function(chunk) {
body+=chunk;
console.log(body);
})
res.on('end', function() {
var parsed = JSON.parse(body);
id = parsed.id;
name = parsed.name;
})
})
});