/fetch-polyfill-http-https

A simple fetch function to use when you need to use a version of node that doesn't have native fetch

Primary LanguageJavaScript

Fetch nodejs polyfill for HTTP & HTTPS

Created: 2022-04-27

 

This is taken from gjuoun's original fetch nodejs polyfill and modified to allow fetching from both HTTP and HTTPS.

 

Note


 

Recommended to use a name like _fetch, so that it won't get confused for any native fetch funtion as shown below

 

Example:

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)
        })
    }