1const https = require('https');
2
3https.get('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', (resp) => {
4 let data = '';
5
6 // A chunk of data has been received.
7 resp.on('data', (chunk) => {
8 data += chunk;
9 });
10
11 // The whole response has been received. Print out the result.
12 resp.on('end', () => {
13 console.log(JSON.parse(data).explanation);
14 });
15
16}).on("error", (err) => {
17 console.log("Error: " + err.message);
18});
19