Created
October 6, 2022 14:23
-
-
Save johnmurch/756b888d54cfce0520891bb1d8597472 to your computer and use it in GitHub Desktop.
Simple https Fetch for JSON (node.js)
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'); | |
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