Skip to content

Instantly share code, notes, and snippets.

@johnmurch
Created October 6, 2022 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmurch/756b888d54cfce0520891bb1d8597472 to your computer and use it in GitHub Desktop.
Save johnmurch/756b888d54cfce0520891bb1d8597472 to your computer and use it in GitHub Desktop.
Simple https Fetch for JSON (node.js)
const https = require('https');
async function fetch(url) {
return new Promise(async (resolve, reject) => {
https.get(url, function (res) {
var body = '';
res.on('data', function (chunk) {
body += chunk;
});
res.on('end', function () {
var payload = JSON.parse(body);
return resolve(payload)
});
}).on('error', function (e) {
reject(e)
});
})
}
async function run(){
let resp = await fetch('https://developers.google.com/search/apis/ipranges/googlebot.json')
console.log(resp)
}
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment