Created
September 9, 2021 07:40
-
-
Save nikostoulas/bdc6330967a37235effc0a27652d4fa8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 received. | |
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); | |
}); | |
}) | |
.on('error', err => { | |
console.log('Error: ' + err.message); | |
}); | |
// Example taken from: 5 Ways to Make HTTP Requests in Node.js - Twilio : https://www.twilio.com/blog/2017/08/http-requests-in-node-js.html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment