{"id":20710038,"url":"https://github.com/oxylabs/proxies-with-node-fetch","last_synced_at":"2026-04-17T16:32:28.506Z","repository":{"id":226453664,"uuid":"768677583","full_name":"oxylabs/proxies-with-node-fetch","owner":"oxylabs","description":"Learn how to use Node-Fetch with proxy servers to make anonymous web requests.","archived":false,"fork":false,"pushed_at":"2025-04-09T08:33:40.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T09:36:03.788Z","etag":null,"topics":["fetch-api","fetch-api-data","fetch-proxies","javascript-web-scraper","js-proxy","node-fetch","node-fetch-example","node-js","node-proxy","node-proxy-server","nodejs","web-proxy","web-proxy-server"],"latest_commit_sha":null,"homepage":"https://oxylabs.io/resources/integrations/node-fetch","language":"JavaScript","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/oxylabs.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-03-07T14:30:15.000Z","updated_at":"2025-04-09T08:33:44.000Z","dependencies_parsed_at":"2025-04-09T09:37:30.995Z","dependency_job_id":null,"html_url":"https://github.com/oxylabs/proxies-with-node-fetch","commit_stats":null,"previous_names":["oxylabs/proxies-with-node-fetch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oxylabs/proxies-with-node-fetch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fproxies-with-node-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fproxies-with-node-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fproxies-with-node-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fproxies-with-node-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxylabs","download_url":"https://codeload.github.com/oxylabs/proxies-with-node-fetch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fproxies-with-node-fetch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31936617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["fetch-api","fetch-api-data","fetch-proxies","javascript-web-scraper","js-proxy","node-fetch","node-fetch-example","node-js","node-proxy","node-proxy-server","nodejs","web-proxy","web-proxy-server"],"created_at":"2024-11-17T02:09:37.992Z","updated_at":"2026-04-17T16:32:28.496Z","avatar_url":"https://github.com/oxylabs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Proxy Integration With Node-Fetch\n\n[![Oxylabs promo code](https://raw.githubusercontent.com/oxylabs/product-integrations/refs/heads/master/Affiliate-Universal-1090x275.png)](https://oxylabs.io/pages/gitoxy?utm_source=877\u0026utm_medium=affiliate\u0026groupid=877\u0026utm_content=proxies-with-node-fetch-github\u0026transaction_id=102f49063ab94276ae8f116d224b67)\n\n[![](https://dcbadge.limes.pink/api/server/Pds3gBmKMH?style=for-the-badge\u0026theme=discord)](https://discord.gg/Pds3gBmKMH) [![YouTube](https://img.shields.io/badge/YouTube-Oxylabs-red?style=for-the-badge\u0026logo=youtube\u0026logoColor=white)](https://www.youtube.com/@oxylabs)\n\nFollow this guide to learn how to use Node-Fetch with proxy servers. You'll see how to integrate Node-Fetch with Oxylabs' [Residential](https://oxylabs.io/products/residential-proxy-pool) and [Datacenter Proxies](https://oxylabs.io/products/datacenter-proxies), as well as [Web Unblocker](https://oxylabs.io/products/web-unblocker), but the steps apply to most proxy services. The guide is also available on the [Oxylabs website](https://oxylabs.io/resources/integrations/node-fetch).\n\n- [Requirements](#requirements)\n  * [Node fetch code example](#node-fetch-code-example)\n- [Integrating proxies](#integrating-proxies)\n  * [Residential Proxies](#residential-proxies)\n  * [Datacenter Proxies](#datacenter-proxies)\n  * [Web Unblocker](#web-unblocker)\n- [Testing proxies](#testing-proxies)\n  * [How to rotate proxies with node fetch](#how-to-rotate-proxies-with-node-fetch)\n  * [Selecting a proxy randomly](#selecting-a-proxy-randomly)\n  * [Iterating over the proxy list](#iterating-over-the-proxy-list)\n\n\n## Requirements\n\nThe first step is installing node.js if you don't have it. Head over to the [downloads](https://node.org/en/download/) page of node.org and download Node. \n\nThe next step is to install the node-fetch package. To install this package, we can use the Node Package Manager tool.\n\n**Important note:** Node Fetch from version 3 is an ESM-only module. In this tutorial, we will be using version 2 so that it remains compatible with CommonJS.\n\nOpen the terminal and navigate to the directory where you want to keep your source code. After that, run the following command to install `node-fetch`:\n\n```bash\nnpm install node-fetch@2 https-proxy-agent\n```\n\n### Node fetch code example\n\nCreate a new file and save it as `check-ip.js`.\n\nThen, load the node-fetch module. To load the module, add the following line of code:\n\n```node\nconst fetch = require(\"node-fetch\");\n```\n\nYou can now use either the `then-catch` syntax as follows:\n\n```node\nfetch(\"https://ip.oxylabs.io/location\")\n  .then((response) =\u003e response.text())\n  .then((data) =\u003e console.log(data))\n  .catch((error) =\u003e console.error(error));\n```\n\nAlternatively, you can use the newer `try-catch` syntax as follows:\n\n```node\n(async () =\u003e {\n  try {\n    const response = await fetch(\"https://ip.oxylabs.io/location\");\n    const data = await response.text();\n    console.log(data);\n  } catch (e) {\n    console.error(e.message);\n  }\n})();\n```\n\nSave this file and open the terminal. Enter the following command to run it:\n\n```bash\nnode check-ip.js\n```\nThe output is your IP address.\n\n## Integrating proxies\n\nTo use proxies, we first need to load the `https-proxy-agent` package. \n\nCreate a new file and save it as `proxies.js`. Add the following lines to load both the required packages:\n\n```node\nconst fetch = require('node-fetch');\nconst { HttpsProxyAgent } = require('https-proxy-agent');\n```\n\nNext, we must create a variable for the http or https proxy URL. \n\nMost proxy servers, such as Oxylabs' Residential and Datacenter proxy servers, require you to authenticate via credentials. In such cases, you can construct the http proxy user as follows:\n\n```node\nconst proxyUrl = `http://${username}:${password}@${proxyServer}`;\n```\n\nWe are using three other local variables to create the proxy URL here. These local variables store your **username**, **password**, and **proxy server**.\n\n### Residential Proxies\n\nThe following example shows how the `https` proxy or the `http` proxy URL would be for Oxylabs Residential Proxies:\n\n```node\nconst proxyUrl = `http://USERNAME:PASSWORD@pr.oxylabs.io:7777`;\n```\n\nHere, `USERNAME` and `PASSWORD` are your Oxylabs proxy user's credentials.\n\nHere, you can use country-specific entries. For example, if you use the proxy server as `au-pr.oxylabs.io:40000` instead of `pr.oxylabs.io:7777`, you'll get an IP in Australia. \n\nPlease see our [documentation](https://developers.oxylabs.io/proxies/residential-proxies/location-settings/country-specific-entry-nodes?_gl=1*t0gn4q*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) for a complete list of country-specific entry nodes and sticky session details.\n\n### Datacenter Proxies\nThe following table summarizes the proxy server configuration for Datacenter Proxies.\n\n| Proxies                                     | Proxy type      | Proxy address         | Port   | User credentials                         | Notes               |\n|---------------------------------------------|-----------------|-----------------------|--------|------------------------------------------|---------------------|\n| Enterprise Dedicated Datacenter Proxies     | `HTTP` or `SOCKS5` | A `selected IP` from the acquired list | `60000`  | Oxylabs proxy user’s username and password | Purchase via sales |\n| Self-Service Dedicated Datacenter Proxies   | `HTTP` or `HTTPS`  | `ddc.oxylabs.io`       | `8001`   | Oxylabs proxy user’s username and password | Purchase via the [dashboard](https://dashboard.oxylabs.io/en/?_gl=1*e17mbt*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) |\n| Shared Datacenter Proxies                   | `HTTP`             | `dc.pr.oxylabs.io`     | `10000`  | Oxylabs proxy user’s username and password | Purchase via the [dashboard](https://dashboard.oxylabs.io/en/?_gl=1*e17mbt*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) |\n\n\n- For **Enterprise Dedicated Datacenter Proxies**, you’ll have to choose an IP address from [the acquired list](https://developers.oxylabs.io/proxies/dedicated-datacenter-proxies/enterprise/proxy-lists?_gl=1*1xwrhcc*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.).\n\n- For **Self-Service Dedicated Datacenter Proxies**, the port indicates [the sequential number](https://developers.oxylabs.io/proxies/dedicated-datacenter-proxies/self-service/proxy-list?_gl=1*1xwrhcc*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) of an IP address from the acquired list.\n\n- For **Shared Datacenter Proxies**, you can also use country-specific entries. For instance, if you enter `dc.fr-pr.oxylabs.io:42000`, you'll have a French exit node. Once again, refer to our [documentation](https://developers.oxylabs.io/proxies/shared-datacenter-proxies/select-country?_gl=1*63hr09*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) for more information and the entire list of country-specific entries.\n\n### Web Unblocker\n\nWhen it comes to Web Unblocker, you have to use the `unblock.oxylabs.io:60000` endpoint and **ignore the SSL certificate**. It supports `HTTP` and `HTTPS` connection protocols. You can also connect to various [geo-locations](https://developers.oxylabs.io/advanced-proxy-solutions/web-unblocker/making-requests/geo-location?_gl=1*63hr09*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.), use [Custom Browser Instructions](https://developers.oxylabs.io/advanced-proxy-solutions/web-unblocker/headless-browser?_gl=1*1p7h7ss*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.), and utilize other functionalities by sending them as request headers. Visit the [documentation](https://developers.oxylabs.io/advanced-proxy-solutions/web-unblocker?_gl=1*1p7h7ss*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) to learn more.\n\n## Testing proxies\n\nNow, it's time to test the proxies. This step would be the same for both Residential Proxies and Datacenter Proxies.\n\nCreate an instance of the `HttpsProxyAgent` class. The constructor of this class takes the proxy URL we have just created:\n\n```node\nconst proxyAgent = new HttpsProxyAgent(proxyUrl);\n```\n\nFinally, we can send this proxy agent to one of the optional parameters of the fetch method—agent. This agent represents an http(s) agent instance, which we have created using the http-proxy-agent package.\n\nPutting together everything, the node fetch proxy code looks as follows:\n\n```node\nconst fetch = require('node-fetch');\nconst { HttpsProxyAgent } = require('https-proxy-agent'); \n\nconst proxyUrl = `http://USERNAME:PASSWORD@pr.oxylabs.io:7777`;\n\n(async () =\u003e {\n  try {\n    const proxyAgent = new HttpsProxyAgent(proxyUrl);\n    const response = await fetch('https://ip.oxylabs.io/location', {\n      agent: proxyAgent,\n    });\n    const data = await response.text();\n    console.log(data);\n  } catch (e) {\n    console.error(e.message);\n  }\n})();\n```\nYou can run this code to see the IP of the proxy address.\n\nIf you want to integrate **Web Unblocker**, you must _ignore the SSL certificate_ by adding an additional line before the `fetch()` function:\n\n```node\n(async () =\u003e {\n  try {\n    const proxyAgent = new HttpsProxyAgent(proxyUrl);\n    process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;\n```\n\n### How to rotate proxies with node fetch\nNotably, while using proxies, most websites will ban the IP if you use the same proxy. The solution is to rotate the IPs.\n\nOxylabs Residential and Shared Datacenter Proxies perform proxy rotation automatically and don't require external rotation.\n\nOur Residential Proxies can either randomly change the proxy address for each request or use the same proxy IP for up to 30 minutes. Shared Datacenter Proxies also offer the above mentioned options but can keep the same IP indefinitely.\n\nSee our documentation for [Residential](https://developers.oxylabs.io/proxies/residential-proxies?_gl=1*ax7hgv*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) and [Shared Datacenter Proxies](https://developers.oxylabs.io/proxies/shared-datacenter-proxies?_gl=1*ax7hgv*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.) to find out more.\n\nDedicated Datacenter Proxies don't have an in-built rotation feature, but they can be implemented with our [Proxy Rotator](https://oxylabs.io/features/proxy-rotator). With this tool, you can easily automate the rotation of our Dedicated Datacenter Proxies.\n\n### Selecting a proxy randomly \nAssuming you have a [proxy list](https://developers.oxylabs.io/proxies/dedicated-datacenter-proxies/proxy-lists?_gl=1*1aho529*_gcl_au*MTQ0Mzk1NzUwNy4xNzA4OTM5Mzk5LjcxNjg3MzQ0My4xNzA5NzM2ODIxLjE3MDk3MzY4MjE.), you can use the following code to rotate the proxies from the given proxy list. Within the example, we run the code three times, each time picking one of the proxies randomly.\n\n```node\nconst fetch = require(\"node-fetch\");\nconst { HttpsProxyAgent } = require('https-proxy-agent'); \n\nproxyUrls =[\n  '127.0.0.1:60000',\n  '127.0.0.2:60000',\n  '127.0.0.3:60000'\n]; \n\n(async () =\u003e {\n  try {\n    for (let i = 0; i \u003c 3; i++) {\n      const randomIndex = Math.floor(Math.random() * proxyUrls.length); // Generate a random index\n      const proxyAgent = new HttpsProxyAgent(proxyUrls[randomIndex]); // Select a proxy URL using the random index\n      const response = await fetch(\"https://ip.oxylabs.io/location\", {\n        agent: proxyAgent,\n      });\n      const data = await response.text();\n      console.log(data);\n    }\n  } catch (e) {\n    console.error(e.message);\n  }\n})();\n```\n\n### Iterating over the proxy list\nYou can modify the above code so that it goes over all the proxies in a sequence too:\n\n```node\n(async () =\u003e {\n  try {\n    for (let i = 0; i \u003c proxyUrls.length; i++) {\n      const proxyAgent = new HttpsProxyAgent(proxyUrls[i]);\n      const response = await fetch(\"https://ip.oxylabs.io/location\", {\n        agent: proxyAgent,\n      });\n      const data = await response.text();\n      console.log(data);\n    }\n  } catch (e) {\n    console.error(e.message);\n  }\n})();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fproxies-with-node-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxylabs%2Fproxies-with-node-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fproxies-with-node-fetch/lists"}