I am making an Http request for some website and that is giving some response
var noOfPages;
const https = require('https');
https.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
data = JSON.parse(data);
noOfPages = data.no_of_pages;
});
})
i am able to use it inside closure but cant access that variable outside of this block. can anyone help me with it?