In my example I'm trying to use a variable outside of the function but no luck yet. Guys can you take a look into and help me to solve this issue? I want to use a variable "value" outside of the function.
var https = require('https');
var options = {
hostname: 'example.com',
port: 443,
path: '/values',
method: 'GET'
};
var req = https.request(options, (res) => {
console.log('statusCode: ', res.statusCode);
console.log('headers: ', res.headers);
res.on('data', (d) => {
var Array = JSON.parse(d);
value = Array[0][1];
console.log(value);
});
});
req.end();
req.on('error', (e) => {
console.error(e);
});