{"id":22489625,"url":"https://github.com/unjs/node-fetch-native","last_synced_at":"2025-06-10T22:41:26.918Z","repository":{"id":39996622,"uuid":"490399940","full_name":"unjs/node-fetch-native","owner":"unjs","description":"better fetch for Node.js. Works on any JavaScript runtime!","archived":false,"fork":false,"pushed_at":"2024-12-02T15:10:54.000Z","size":491,"stargazers_count":167,"open_issues_count":12,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-12-03T15:49:24.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-09T18:27:15.000Z","updated_at":"2024-12-03T11:32:55.000Z","dependencies_parsed_at":"2023-02-14T07:45:35.095Z","dependency_job_id":"859df906-670b-455d-870a-cd4b1dee92e8","html_url":"https://github.com/unjs/node-fetch-native","commit_stats":{"total_commits":178,"total_committers":7,"mean_commits":"25.428571428571427","dds":0.4887640449438202,"last_synced_commit":"fd914e9d89b9bdfe9077a44745dec1e0bad7e494"},"previous_names":["unjs/node-fetch-compat"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fnode-fetch-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fnode-fetch-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fnode-fetch-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fnode-fetch-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/node-fetch-native/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228500393,"owners_count":17930057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T17:20:19.369Z","updated_at":"2025-06-10T22:41:26.906Z","avatar_url":"https://github.com/unjs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# node-fetch-native\n\n[![][npm-version-src]][npm-version-href]\n[![][github-actions-src]][github-actions-href]\n[![][packagephobia-src]][packagephobia-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n\n\u003c!-- [![Codecov][codecov-src]][codecov-href] --\u003e\n\nA redistribution of [node-fetch v3](https://github.com/node-fetch/node-fetch) (+ more!) for better backward and forward compatibility.\n\n**Why this package?**\n\n- We can no longer `require('node-fetch')` with the latest version. This stopped popular libraries from upgrading and dependency conflicts between `node-fetch@2` and `node-fetch@3`.\n- 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.\n- With the introduction of native fetch to Node.js via [undici](https://github.com/nodejs/undici) there is no easy way to support http proxies!\n\n**Features:**\n\n✅ Prefer to **native globals** when available (See Node.js [experimental fetch](https://nodejs.org/dist/latest-v17.x/docs/api/cli.html#--experimental-fetch)).\n\n✅ Compact build and less install size with **zero dependencies** [![][packagephobia-s-src]][packagephobia-s-href] \u003csup\u003evs\u003c/sup\u003e [![][packagephobia-s-alt-src]][packagephobia-s-alt-href]\n\n✅ Support both **CommonJS** (`require`) and **ESM** (`import`) usage\n\n✅ Use native version if imported without `node` condition using [conditional exports](https://nodejs.org/api/packages.html#packages_conditional_exports) with **zero bundle overhead**\n\n✅ Polyfill support for Node.js\n\n✅ Compact and simple proxy supporting both Node.js versions without native fetch using [HTTP Agent](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent) and versions with native fetch using [Undici Proxy Agent](https://undici.nodejs.org/#/docs/api/ProxyAgent)\n\n## Usage\n\nInstall `node-fetch-native` dependency:\n\n```sh\n# npm\nnpm i node-fetch-native\n\n# yarn\nyarn add node-fetch-native\n\n# pnpm\npnpm i node-fetch-native\n```\n\nYou can now either import or require the dependency:\n\n```js\n// ESM\nimport fetch from \"node-fetch-native\";\n\n// CommonJS\nconst fetch = require(\"node-fetch-native\");\n```\n\nMore named exports:\n\n```js\n// ESM\nimport {\n  fetch,\n  Blob,\n  FormData,\n  Headers,\n  Request,\n  Response,\n  AbortController,\n} from \"node-fetch-native\";\n\n// CommonJS\nconst {\n  fetch,\n  Blob,\n  FormData,\n  Headers,\n  Request,\n  Response,\n  AbortController,\n} = require(\"node-fetch-native\");\n```\n\n## Force using non-native version\n\nSometimes you want to explicitly use none native (`node-fetch`) implementation of `fetch` in case of issues with the native/polyfill version of `globalThis.fetch` with Node.js or runtime environment.\n\nYou have two ways to do this:\n\n- Set the `FORCE_NODE_FETCH` environment variable before starting the application.\n- Import from `node-fetch-native/node`\n\n## Disable runtime check\n\nOnce the `node-fetch-native/node` module is loaded, it pushes a log warning if the current runtime differs from the Node.js. Set the `DISABLE_NODE_FETCH_NATIVE_WARN` environment variable to turn this check off.\n\n## Polyfill support\n\nUsing the polyfill method, we can ensure global fetch is available in the environment and all files. Natives are always preferred.\n\n**Note:** I don't recommend this if you are authoring a library! Please prefer the explicit methods.\n\n```js\n// ESM\nimport \"node-fetch-native/polyfill\";\n\n// CJS\nrequire(\"node-fetch-native/polyfill\");\n\n// You can now use fetch() without any import!\n```\n\n## Proxy Support\n\nNode.js has no built-in support for HTTP Proxies for fetch (see [nodejs/undici#1650](https://github.com/nodejs/undici/issues/1650) and [nodejs/node#8381](https://github.com/nodejs/node/issues/8381))\n\nThis package bundles a compact and simple proxy-supported solution for both Node.js versions without native fetch using [HTTP Agent](https://github.com/TooTallNate/proxy-agents/tree/main/packages/proxy-agent) and versions with native fetch using [Undici Proxy Agent](https://undici.nodejs.org/#/docs/api/ProxyAgent).\n\nBy default, `https_proxy`, `http_proxy`, `HTTPS_PROXY`, and `HTTP_PROXY` environment variables will be checked and used (in order) for the proxy and if not any of them are set, the proxy will be disabled. You can override it using the `url` option passed to `createFetch` and `createProxy` utils.\n\nBy default, `no_proxy` and `NO_PROXY` environment variables will be checked and used for the (comma-separated) list of hosts to ignore the proxy for. You can override it using the `noProxy` option passed to `createFetch` and `createProxy` utils. The entries starting with a dot will be used to check the domain and also any subdomain.\n\n\u003e [!NOTE]\n\u003e Using export conditions, this utility adds proxy support for Node.js and for other runtimes, it will simply return native fetch.\n\n### `fetch` with proxy support\n\nYou can simply import `{ fetch }` from `node-fetch-native/proxy` with a preconfigured `fetch` function that has proxy support.\n\n```ts\nimport { fetch } from \"node-fetch-native/proxy\";\n\nconsole.log(await fetch(\"https://icanhazip.com\").then((r) =\u003e r.text()));\n```\n\n### `createFetch` utility\n\nYou can use the `createFetch` utility to instantiate a `fetch` instance with custom proxy options.\n\n```ts\nimport { createFetch } from \"node-fetch-native/proxy\";\n\nconst fetch = createFetch({ url: \"http://localhost:9080\" });\n\nconsole.log(await fetch(\"https://icanhazip.com\").then((r) =\u003e r.text()));\n```\n\n### `createProxy` utility\n\n`createProxy` returns an object with `agent` and `dispatcher` keys that can be passed as fetch options.\n\n```ts\nimport { fetch } from \"node-fetch-native\";\nimport { createProxy } from \"node-fetch-native/proxy\";\n\nconst proxy = createProxy();\n// const proxy = createProxy({ url: \"http://localhost:8080\" });\n\nconsole.log(\n  await fetch(\"https://icanhazip.com\", { ...proxy }).then((r) =\u003e r.text()),\n);\n```\n\n## Alias to `node-fetch`\n\nUsing 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`.\n\n### npm\n\nUsing npm [overrides](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides):\n\n```jsonc\n// package.json\n{\n  \"overrides\": {\n    \"node-fetch\": \"npm:node-fetch-native@latest\",\n  },\n}\n```\n\n### yarn\n\nUsing yarn [selective dependency resolutions](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/):\n\n```jsonc\n// package.json\n{\n  \"resolutions\": {\n    \"node-fetch\": \"npm:node-fetch-native@latest\",\n  },\n}\n```\n\n### pnpm\n\nUsing [pnpm.overrides](https://pnpm.io/package_json#pnpmoverrides):\n\n```jsonc\n// package.json\n{\n  \"pnpm\": {\n    \"overrides\": {\n      \"node-fetch\": \"npm:node-fetch-native@latest\",\n    },\n  },\n}\n```\n\n## License\n\nMade with 💛 Published under the [MIT](./LICENSE) license.\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://flat.badgen.net/npm/v/node-fetch-native\n[npm-version-href]: https://npmjs.com/package/node-fetch-native\n[npm-downloads-src]: https://flat.badgen.net/npm/dm/node-fetch-native\n[npm-downloads-href]: https://npmjs.com/package/node-fetch-native\n[github-actions-src]: https://flat.badgen.net/github/checks/unjs/node-fetch-native\n[github-actions-href]: https://github.com/unjs/node-fetch-native/actions?query=workflow%3Aci\n[packagephobia-src]: https://flat.badgen.net/packagephobia/install/node-fetch-native\n[packagephobia-href]: https://packagephobia.com/result?p=node-fetch-native\n[packagephobia-s-src]: https://flat.badgen.net/packagephobia/install/node-fetch-native?label=node-fetch-native\u0026scale=.9\n[packagephobia-s-href]: https://packagephobia.com/result?p=node-fetch-native\n[packagephobia-s-alt-src]: https://flat.badgen.net/packagephobia/install/node-fetch?label=node-fetch\u0026scale=.9\n[packagephobia-s-alt-href]: https://packagephobia.com/result?p=node-fetch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fnode-fetch-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Fnode-fetch-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fnode-fetch-native/lists"}