Skip to content
ProxyHub
All guides

Scripts and development

Use the proxy in Node.js

In Node.js 18+ fetch is built on undici: with its ProxyAgent you pass the HTTP proxy to every request. Install undici with npm install undici.

Step by step

  1. 1

    Set the proxy protocol to HTTP in the client area.

  2. 2

    Install undici and create a ProxyAgent with the proxy URL, username and password included.

  3. 3

    Pass the agent to fetch with the dispatcher option.

  4. 4

    For a new IP, call the rotation link and wait about 20 seconds.

JavaScript
import { fetch, ProxyAgent } from "undici";

const dispatcher = new ProxyAgent("http://USER:PASSWORD@HOST:PORT");

const ip = await (await fetch("https://api.ipify.org", { dispatcher })).text();
console.log(ip);

// New IP
await fetch("ROTATION_LINK");
await new Promise((r) => setTimeout(r, 20_000));

Replace USER, PASSWORD, HOST and PORT with your proxy's data (client area › proxy › Connection).

Tips

Don't have a proxy yet?

Choose country, carrier and plan: the proxy activates right away.

See plans

Need a hand?

Dedicated 24/7 support on Telegram helps you set up any tool.

Message us on Telegram

More guides