# node-fetch-cjs

> A wrapper for node-fetch (a light-weight module that brings Fetch API to node.js) to be used in commonjs environment.

Latest version **3.3.2** (published 2023-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-fetch-cjs
pnpm add node-fetch-cjs
yarn add node-fetch-cjs
bun add node-fetch-cjs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.3.2 |
| Published | 2023-09-12 |
| First published | 2021-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 229.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Touchify |
| Maintainers | mluce |
| Keywords | fetch, http, promise, request, curl, wget, xhr, whatwg, cjs, commonjs |

## Links

- npm: https://www.npmjs.com/package/node-fetch-cjs
- Repository: https://github.com/touchifyapp/node-fetch-cjs
- Homepage: https://github.com/node-fetch/node-fetch
- Issues: https://github.com/node-fetch/node-fetch/issues
- Funding: https://opencollective.com/node-fetch
- npm.io page: https://npm.io/package/node-fetch-cjs

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 3.3.2 (latest) — 2023-09-12
- 3.2.10 — 2022-07-31
- 3.2.9 — 2022-07-19
- 3.2.8 — 2022-07-13
- 3.2.7 — 2022-07-12
- 3.2.6 — 2022-06-10
- 3.2.5 — 2022-06-02
- 3.2.4 — 2022-04-28
- 3.2.3 — 2022-03-12
- 3.2.1 — 2022-03-01
- 4.0.0-beta.4 — 2022-01-28
- 4.0.0-beta.1 — 2022-01-27
- 3.2.0 — 2022-01-21
- 3.1.1 — 2022-01-17
- 3.1.0-fix.1 — 2021-11-24
- … 2 more at https://npm.io/package/node-fetch-cjs/versions

## README

# Node Fetch CJS

This package is a wrapper for [Node Fetch v3](https://github.com/node-fetch/node-fetch) 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](https://esbuild.github.io) 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

```bash
$ npm install node-fetch-cjs
```

## Usage

Destructuring export (recommended):
```javascript
const { default: fetch, Headers } = require("node-fetch-cjs");

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

const headers = new Headers();
```

Legacy export:
```javascript
const fetch = require("node-fetch-cjs");

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

const headers = new fetch.Headers();
```

## Full documentation

Full documentation is available on the [node-fetch](https://github.com/node-fetch/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:

```javascript
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](https://github.com/node-fetch/node-fetch) for their work to allow all of us to use `fetch` in Node.JS environments.

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/node-fetch-cjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
