3.3.2 • Published 8 months ago

node-fetch-cjs v3.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Node Fetch CJS

This package is a wrapper for Node Fetch v3 for commonjs environments.

Motivation

Since v3, node-fetch only provides an ESM version of the package.

While this choice is a good choice for the future, it is impacting a lot of codebases built on commonjs environment. Some of them could update their code to import node-fetch using native import() but many could not. This is especially true for TypeScript users who cannot mix commonjs and ESM imports in their projects.

This module bundles node-fetch using esbuild and apply some custom transformations to make sure it works in commonjs environments.

If you are able to migrate to the official v3 release of node-fetch, we highly recommend to use the official node-fetch. This package is built to help users who could not migrate easily.

This repository is automatically updated when a new version of node-fetch is released

Installation

$ npm install node-fetch-cjs

Usage

Destructuring export (recommended):

const { default: fetch, Headers } = require("node-fetch-cjs");

fetch(/* ... */).then(/* ... */);

const headers = new Headers();

Legacy export:

const fetch = require("node-fetch-cjs");

fetch.default(/* ... */).then(/* ... */);

const headers = new fetch.Headers();

Full documentation

Full documentation is available on the node-fetch repository.

Differences

In order to be fully CJS compatible, we had to bundle dependencies from node-fetch directly into this package. This means that both fetch-blob and formdata-polyfill are bundled.

For your convenience, these dependencies are exported to allow you to use them in your code:

const { Blob, FormData } = require("node-fetch-cjs");

const blob = new Blob(["content"], { type: "text/plain" });
const text = await blob.text();

const data = new FormData();
data.append("key", "value");

TypeScript

Types are bundled with node-fetch-cjs, so you don't need to install any additional packages.

Acknowledgement

Thanks to node-fetch/node-fetch for their work to allow all of us to use fetch in Node.JS environments.

License

MIT

3.3.2

8 months ago

3.2.6

2 years ago

3.2.5

2 years ago

3.2.10

2 years ago

3.2.9

2 years ago

3.2.8

2 years ago

3.2.7

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.1

2 years ago

4.0.0-beta.4

2 years ago

4.0.0-beta.1

2 years ago

3.1.0

2 years ago

3.1.0-fix.1

2 years ago

3.0.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago