{"id":15706811,"url":"https://github.com/silverwind/fetch-enhanced","last_synced_at":"2026-05-07T02:05:27.581Z","repository":{"id":57234564,"uuid":"296139858","full_name":"silverwind/fetch-enhanced","owner":"silverwind","description":"fetch wrapper with support for automatic HTTP proxy and timeout","archived":false,"fork":false,"pushed_at":"2024-07-18T11:25:43.000Z","size":1580,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T13:37:18.096Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/silverwind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-09-16T20:22:48.000Z","updated_at":"2024-07-18T11:25:47.000Z","dependencies_parsed_at":"2024-03-26T02:33:19.767Z","dependency_job_id":"cd485aad-2967-4f00-9c06-ac175849dfbb","html_url":"https://github.com/silverwind/fetch-enhanced","commit_stats":{"total_commits":186,"total_committers":1,"mean_commits":186.0,"dds":0.0,"last_synced_commit":"c7ed7f8f7a9a3aabaf1366e8dc916d655d93817f"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Ffetch-enhanced","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Ffetch-enhanced/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Ffetch-enhanced/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silverwind%2Ffetch-enhanced/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silverwind","download_url":"https://codeload.github.com/silverwind/fetch-enhanced/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253766399,"owners_count":21960907,"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-10-03T20:28:50.337Z","updated_at":"2026-05-07T02:05:22.530Z","avatar_url":"https://github.com/silverwind.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fetch-enhanced\n[![](https://img.shields.io/npm/v/fetch-enhanced.svg?style=flat)](https://www.npmjs.org/package/fetch-enhanced) [![](https://img.shields.io/npm/dm/fetch-enhanced.svg)](https://www.npmjs.org/package/fetch-enhanced) [![](https://packagephobia.com/badge?p=updates)](https://packagephobia.com/result?p=fetch-enhanced)\n\n`fetch-enhanced` wraps a provided `fetch`-like function like [undici](https://nodejs.org/dist/latest-v18.x/docs/api/globals.html#fetch) or [node-fetch](https://github.com/node-fetch/node-fetch) and adds:\n\n- HTTP Proxy discovery from standard environment variables\n- HTTP Request Timeout support\n- Accessible [agent/dispatcher](https://nodejs.org/api/https.html#https_new_agent_options) [options](https://nodejs.org/api/http.html#http_new_agent_options)\n\n## Usage\n\n```js\nimport {fetch as undiciFetch} from \"undici\";\nimport fetchEnhanced from \"fetch-enhanced\";\n\nconst fetch = fetchEnhanced(undiciFetch, {undici: true});\nawait fetch(\"https://example.com\");\n```\n\n## API\n### fetchEnhanced(fetchImplementation, opts)\n\n- fetchImplementation: *Function* A `fetch`-like module that takes `(url, opts)` and a `agent` (like `node-fetch`) or `dispatcher` (like `undici`) option.\n- `opts` *Object* Required.\n  - `agentCacheSize`: *number* Size of the agent cache. Default: `512`.\n  - `undici`: *boolean* Whether the fetch implementation is undici. Required.\n\nReturns: A wrapped `fetch` function.\n\n### fetch(url, [opts])\n\n- `opts` *Object*\n  - `timeout`: *number* Request timeout in milliseconds. Default: 0 (meaning no timeout).\n  - `noProxy`: *boolean* Explicitely disable any proxy server use. Default: false.\n  - `agent`: *http.Agent* Custom HTTP agent. When specified, proxy discovery will no longer work.\n  - `agentOpts`: *object* [Agent](https://nodejs.org/api/https.html#https_new_agent_options) or [Dispatcher](https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md#parameter-proxyagentoptions) [options](https://nodejs.org/api/http.html#http_new_agent_options).Default: `{maxSockets: 64, keepAlive: false}`\n    - `agentOpts.noProxy`: *boolean* Do not use proxy in any case. Default: `false`.\n  - Any valid `fetch` module option, like for [`node-fetch`](https://github.com/node-fetch/node-fetch#options)\n\n### TimeoutError\n\nError class that can be used for `err instanceof TimeoutError`:\n\n```js\nimport {TimeoutError} from \"fetch-enhanced\";\n\ntry {\n  await fetch(\"https://example.com\", {timeout: 0});\n} catch (err) {\n  console.log(err instanceof TimeoutError);\n  // =\u003e true\n}\n```\n\n### fetch.clearCache()\n\nClear the agent cache and destroys all cached agents. This is generally only neccessary when the proxy environment variables are expected to change during runtime.\n\n```js\nprocess.env.HTTPS_PROXY = \"https://proxy1.dev\";\nawait fetch(\"https://example.com\");\nfetch.clearCache();\nprocess.env.HTTPS_PROXY = \"https://proxy2.dev\";\nawait fetch(\"https://example.com\");\n```\n\n© [silverwind](https://github.com/silverwind), distributed under BSD licence\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilverwind%2Ffetch-enhanced","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilverwind%2Ffetch-enhanced","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilverwind%2Ffetch-enhanced/lists"}