A better redistribution of node-fetch

Overview

node-fetch-native

A redistribution of node-fetch v3 for better backward and forward compatibility.

Why this package?

  • We can no longer require('node-fetch') with latest version. This stopped popular libraries from upgrading and dependency conflicts between node-fetch@2 and node-fetch@3.
  • With upcoming versions of Node.js, native fetch is being supported. We are prepared for native fetch support using this package yet keep supporting older Node versions.

Features:

Prefer to native globals when available (See Node.js experimental fetch)

Compact build and less install size with zero dependencies vs

Support both CommonJS (require) and ESM (import) usage

Use native version if imported without node condition using conditional exports with zero bundle overhead

Polyfill support for Node.js

Usage

Install node-fetch-native dependency:

# npm
npm i node-fetch-native

# yarn
yarn add node-fetch-native

# pnpm
pnpm i node-fetch-native

You can now either import or require the dependency:

// ESM
import fetch from 'node-fetch-native'

// CommonJS
const fetch = require('node-fetch-native')

More named exports:

// ESM
import { fetch, Blob, FormData, Headers, Request, Response, AbortController } from 'node-fetch-native'

// CommonJS
const { fetch, Blob, FormData, Headers, Request, Response, AbortController } = require('node-fetch-native')

Polyfill support

Using the polyfill method, we can once ensure global fetch is available in the environment and all files. Natives are always preferred.

Note: I don't recommand this if you are authoring a library! Please prefer explicit methods.

// ESM
import 'node-fetch-native/polyfill'

// CJS
require('node-fetch-native/polyfill')

// You can now use fetch() without any import!

Alias to node-fetch

Using this method, you can ensure all project dependencies and usages of node-fetch can benefit from improved node-fetch-native and won't conflict between node-fetch@2 and node-fetch@3.

npm

Using npm overrides:

// package.json
{
  "overrides": {
    "node-fetch": "npm:node-fetch-native@latest"
  }
}

yarn

Using yarn selective dependency resolutions:

// package.json
{
  "resolutions": {
    "node-fetch": "npm:node-fetch-native@latest"
  }
}

pnpm

Using pnpm.overrides:

// package.json
{
  "pnpm": {
    "overrides": {
      "node-fetch": "npm:node-fetch-native@latest"
    }
  }
}

License

Made with 💛

node-fetch is published under the MIT license

Comments
Owner
unjs
Unified JavaScript Tools
unjs
This simple project, show how work with async Fetch, function component and class component

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

DaliyaAsel 2 Feb 17, 2022
Easily fetch infos from Goyabu.com

goyabu A easy and simple way to get data from Goyabu.com. Note that the package only catches the first result, so if you want the second season of Shi

Luis Gabriel Araújo 2 Jan 28, 2022
This simple project aims to connect to an API to fetch score data and display it on a LeaderBoard box, as well as provide the tool to submit a new score.

Leader Board: Hit the API! This simple project aims to connect to an API to fetch score data and display it on a LeaderBoard box, as well as provide t

Andrés Felipe Arroyave Naranjo 12 Apr 6, 2022
A collection of Javascript scripts running with Alchemy Web3.js, Fetch, or Axios

Alchemy NFT API Javascript Scripts Clone the repo, install dependencies, and try the API out! Clone git clone [email protected]:alchemyplatform/nft-api-j

Alchemy 47 Nov 29, 2022
A NodeJs service which allows you to create a movie based on it's title (additional movie details will be fetched) and fetch all created movies.

movies-api A NodeJs service which allows you to create a movie based on it's title (additional movie details will be fetched) and fetch all created mo

Ugochukwu Ejiogu 2 Mar 27, 2022
Search, fetch, and get data regarding United States presidents.

us-presidents Search, fetch, and get data regarding United States presidents. GitHub Documention Discord Examples Installation NPM npm install us-pres

Spen 3 May 7, 2022
"Choose your Pokemon" is a Webpack project meant to fetch data from two different APIs: PokéAPI and Involvement API

"Choose your Pokemon" is a Webpack project meant to fetch data from two different APIs: PokéAPI and Involvement API. Here we display a list of 20 Pokemons for whom one can like, display more info, and comment; all based on the data from these two external resources.

Carlos HerverSolano 19 Mar 31, 2022
A script for Obsidian's QuickAdd plugin, to fetch books data using Google Books API.

Books script for Obsidian's Quickadd plugin Demo If this script helped you and you wish to contribute :) Description This script allows you to easily

Elaws 10 Dec 31, 2022
API and CLI tool to fetch and query Chome DevTools heap snapshots.

Puppeteer Heap Snapshot Capture heap snapshots and query the snapshot for objects matching a set of properties. Read more about it in this blog post.

Adrian Cooney 858 Jan 3, 2023
Script to fetch all NFT owners using moralis API. This script output is a data.txt file containing all owner addresses of a given NFT and their balances.

?? Moralis NFT Snapshot Moralis NFT API will only return 500 itens at a time when its is called. For that reason, a simple logic is needed to fetch al

Phill Menezes 6 Jun 23, 2022
Window.fetch polyfill

window.fetch polyfill This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to uphold this code. [co

null 38 Sep 11, 2020
Fetch publication metadata from the INSPIRE-HEP database

Zotero INSPIRE Metadata Updater This is an add-on for the excellent open-source reference manager Zotero. It is useful as most papers from arXiv will

null 20 Nov 27, 2022
fetch and process data in web worker, store in indexedDB.

Query+ install yarn add query-plus or pnpm add query-plus or npm install query-plus import import { useFetch, usePreFetch } from "query-plus" use

Rod Lewis 5 Aug 29, 2022
fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

立党 Lidang 4 Sep 20, 2022
A React hook to fetch ENS records from a domain.

use-ens A React hook to fetch ENS records from a domain. Install pnpm i use-ens Example import React, { useEffect } from 'react' import { useWeb3React

v 1 r t l 17 Jul 31, 2022
A Fetch API-compatible PlanetScale database driver

PlanetScale Serverless Driver for JavaScript A Fetch API-compatible PlanetScale database driver for serverless and edge compute platforms that require

PlanetScale 255 Dec 27, 2022
⏬ Fetch the most up-to-date ABI of verified Smart Contracts (including proxy implementations) from Etherscan in seconds!

etherscan-abi ⏬ ?? Fetch the most up-to-date ABI of verified Smart Contracts (including proxy implementations) from Etherscan in seconds! Usage CLI Fe

Romain Milon 6 Dec 27, 2022
An even simpler wrapper around native Fetch to strip boilerplate from your fetching code!

Super lightweight (~450 bytes) wrapper to simplify native fetch calls using any HTTP method (existing or imagined). Features Fully typed/TypeScript su

Kevin R. Whitley 49 Dec 28, 2022
A MITM cache between RPCs and a a dAPP. Useful to allow for better performance on a public RPC node

better-cosmos-rpcs A cheaper way to allow for public RPCs as a service WITHOUT scaling issues. No need to rate limit either. How it is done: User GET

Reece Williams 3 Nov 19, 2022