Skip to content

Instantly share code, notes, and snippets.

@nikostoulas
Created September 9, 2021 07:40
Show Gist options
  • Save nikostoulas/bdc6330967a37235effc0a27652d4fa8 to your computer and use it in GitHub Desktop.
Save nikostoulas/bdc6330967a37235effc0a27652d4fa8 to your computer and use it in GitHub Desktop.
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