Created: 2022-04-27
This is taken from gjuoun's original fetch nodejs polyfill and modified to allow fetching from both HTTP and HTTPS.
Recommended to use a name like _fetch for your function, so that it wont get confused for any native fetch funtions as shown below
const _fetch = require("./fetch")
fetchExample(){
_fetch('http://testexample.com/json', {}, true)
.then(res => res.json())
.then(data => {
console.log(data)
})
.catch(error => {
console.log(error)
})
}