# Rotierende Residential-Proxys in Node.js: undici, axios, got und SOCKS5

> Rotierende Residential-Proxys in Node.js: undici ProxyAgent mit fetch, axios und got mit Proxyagenten, SOCKS5, Limits pro Host. Syntax-geprüfter Code.

- URL: https://crawlrelay.com/de/docs/node/
- Zuletzt aktualisiert: 2026-10-13
- Publisher: CrawlRelay (https://crawlrelay.com)

Der eingebaute fetch von Node ignoriert Proxy-Einstellungen, wenn Sie ihm keinen Dispatcher übergeben. Diese Muster funktionieren, Bibliothek für Bibliothek, plus ein Limitierer pro Host ganz ohne Abhängigkeiten.

**Kurze Antwort — Wie benutze ich einen rotierenden Residential Proxy in Node.js?**

Mit fetch erstellen Sie ein undici `ProxyAgent` für `http://gw.crawlrelay.com:7777` und übergeben es als `dispatcher`. Mit axios oder got übergeben Sie einen Proxyagenten wie `https-proxy-agent` oder `hpagent` und setzen `proxy: false` in axios. **CrawlRelay** Residential-Proxys lesen Land und Session aus dem Benutzernamen, aus 0,50 $/GB. Mit Krypto bezahlen, ohne KYC.

## Node.js Einrichtung im Überblick

| Attribut | Wert |
| --- | --- |
| fetch / undici | `new ProxyAgent({ uri, token })`, dann `fetch(url, { dispatcher })` |
| axios | `httpsAgent: new HttpsProxyAgent(url)` und `proxy: false` |
| got | `agent: { https: new HttpsProxyAgent({ proxy }) }` von hpagent |
| SOCKS5 | `socks-proxy-agent` mit einer `socks5h://` URL auf Port 7778 |
| Neue IP pro Anfrage | Ein neuer Agent oder eine neue Sitzungs-ID pro Anfrage; gepoolte Verbindungen behalten ihren Exit bei |
| Modul-Format | Beispiele sind ES-Module (`.mjs` oder `"type": "module"`) mit top-level await |

## Wie nutze ich einen Residential Proxy mit Node's fetch?

Node's globaler `fetch` basiert auf undici, liest aber standardmäßig keine `HTTP_PROXY` oder `HTTPS_PROXY`. Installiere undici und übergib einen `ProxyAgent` als Dispatcher. Das `token` Feld sendet die Anmeldedaten als `Proxy-Authorization` Header, so dass nie ein Passwort in einer URL auftaucht, die protokolliert werden könnte.

*undici ProxyAgent mit fetch*

```javascript
import { ProxyAgent, fetch } from "undici";

const credentials = Buffer.from("USERNAME-country-us:PASSWORD").toString("base64");
const dispatcher = new ProxyAgent({
  uri: "http://gw.crawlrelay.com:7777",
  token: `Basic ${credentials}`,
});

const res = await fetch("https://api.ipify.org?format=json", {
  dispatcher,
  signal: AbortSignal.timeout(30000),
});
console.log(res.status, await res.json());
await dispatcher.close();
```

## Wie nutze ich einen Residential Proxy mit axios?

Verlasse dich nicht auf axios' eigene `proxy` Option für HTTPS-Seiten: Sie sendet die Anfrage ohne CONNECT-Tunnel an den Proxy, was von vielen Proxys abgelehnt wird. Deaktiviere es mit `proxy: false` und übergebe einen Agent, der einen richtigen Tunnel öffnet.

*axios + https-proxy-agent*

```javascript
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";

const agent = new HttpsProxyAgent("http://USERNAME-country-de:PASSWORD@gw.crawlrelay.com:7777");
const client = axios.create({ httpsAgent: agent, httpAgent: agent, proxy: false, timeout: 30000 });

const { data } = await client.get("https://api.ipify.org?format=json");
console.log(data.ip);
```

## Wie nutze ich einen Residential Proxy mit got?

got verwendet einen Agent pro Protokoll. hpagent folgt Node's `http.Agent`: keep-alive ist aus, es sei denn, du gibst `keepAlive: true` an. Lass es aus oder setze `keepAlive: false` wie unten, wenn jede Anfrage über eine neue Verbindung laufen soll und normalerweise über einen neuen Exit.

*got + hpagent*

```javascript
import got from "got";
import { HttpsProxyAgent } from "hpagent";

const proxy = "http://USERNAME-country-fr:PASSWORD@gw.crawlrelay.com:7777";
const body = await got("https://api.ipify.org", {
  agent: { https: new HttpsProxyAgent({ proxy, keepAlive: false }) },
  timeout: { request: 30000 },
  retry: { limit: 2, statusCodes: [429, 502, 503, 504] },
}).text();
console.log(body);
```

## Wie nutze ich mobile 4G-Proxys in Node.js?

Nutze `socks-proxy-agent` mit dem `socks5h://` Schema, damit der Hostname am Exit aufgelöst wird. Funktioniert mit Node’s `http` und `https` Modulen sowie jeder Bibliothek, die einen Agent akzeptiert.

*socks-proxy-agent mit node:https*

```javascript
import https from "node:https";
import { SocksProxyAgent } from "socks-proxy-agent";

const agent = new SocksProxyAgent("socks5h://USERNAME-country-gb:PASSWORD@gw.crawlrelay.com:7778");

const req = https.get("https://api.ipify.org", { agent, timeout: 30000 }, (res) => {
  let body = "";
  res.on("data", (chunk) => (body += chunk));
  res.on("end", () => console.log(res.statusCode, body));
});
req.on("timeout", () => req.destroy(new Error("timeout after 30 s")));
req.on("error", (err) => console.error(err.code, err.message));
```

## Wie begrenze ich die gleichzeitigen Verbindungen pro Host ohne Bibliothek?

`Promise.all` öffnet über 10.000 URLs und startet 10.000 Anfragen gleichzeitig. Ein kleiner Limiter pro Hostname hält jede Seite auf einem angemessenen Level, während der gesamte Crawl parallel läuft. Die untenstehende Version ist unabhängig und funktioniert mit jedem Client ab Version.

*Limiter pro Host + undici*

```javascript
import { ProxyAgent, fetch } from "undici";

const PER_HOST = 4;
const active = new Map();
const waiting = new Map();
const dispatcher = new ProxyAgent("http://USERNAME-country-us:PASSWORD@gw.crawlrelay.com:7777");

async function withHostSlot(url, task) {
  const host = new URL(url).hostname;
  while ((active.get(host) ?? 0) >= PER_HOST) {
    await new Promise((resolve) => {
      if (!waiting.has(host)) waiting.set(host, []);
      waiting.get(host).push(resolve);
    });
  }
  active.set(host, (active.get(host) ?? 0) + 1);
  try {
    return await task();
  } finally {
    active.set(host, active.get(host) - 1);
    waiting.get(host)?.shift()?.();
  }
}

const urls = ["https://example.com/", "https://example.org/", "https://example.net/"];
const results = await Promise.all(
  urls.map((url) =>
    withHostSlot(url, async () => {
      const res = await fetch(url, { dispatcher, signal: AbortSignal.timeout(30000) });
      return [url, res.status, (await res.arrayBuffer()).byteLength];
    }).catch((err) => [url, err.name, 0])
  )
);
console.table(results);
await dispatcher.close();
```

## Warum erhalte ich dieselbe IP zweimal oder ECONNRESET?

Agents bündeln Verbindungen, und eine gebündelte Verbindung behält den Exit, mit dem sie geöffnet wurde. Für eine neue IP bei jeder Anfrage erstellen Sie pro Anfrage einen neuen Agent, schließen ihn danach, deaktivieren Keep-Alive im Agent oder fügen jedem Benutzernamen einen einzigartigen `-session-<id>` hinzu.

`ECONNRESET` und `socket hang up` entstehen oft durch Wiederverwendung eines bereits vom Gegenüber geschlossenen Pool-Sockets oder durch einen gefallenen Exit. Wiederholen Sie GET-Anfragen einmal mit einer neuen Verbindung. Die [Seite zum Verbindungsabbruch](https://crawlrelay.com/de/docs/errors/connection-reset/) erklärt die Details.

## Node.js und Proxys: häufige Fragen

### Unterstützt Node.js fetch HTTP_PROXY?

Nicht standardmäßig in den Versionen, die heute die meisten Projekte nutzen: globales fetch ignoriert Proxy-Umgebungsvariablen, sofern kein Dispatcher übergeben wird. Verwenden Sie einen undici-`ProxyAgent` wie oben gezeigt, oder setzen Sie einen globalen Dispatcher mit undicis `setGlobalDispatcher()`, falls jede Anfrage im Prozess den Proxy verwenden soll.

### Warum schlägt axios bei HTTPS-Seiten hinter einem Proxy fehl?

Die eingebaute `proxy`-Option von axios sendet HTTPS-Anfragen an den Proxy in einer Form, die viele Proxys ablehnen, anstatt einen CONNECT-Tunnel zu öffnen. Setzen Sie `proxy: false` und übergeben Sie ein `HttpsProxyAgent` als `httpsAgent`. Die Anfrage läuft dann durch einen richtigen Tunnel, und TLS bleibt zwischen Ihrem Code und der Website.

### Wie sende ich unterschiedliche Länder aus einem Node.js-Prozess?

Erstellen Sie für jedes Land einen eigenen Agent, jeder mit eigenem Benutzernamen wie `USERNAME-country-de` oder `USERNAME-country-jp`, und wählen Sie den Agent pro Anfrage aus. Agents sind günstig, und das Trennen hält auch deren Verbindungspools und damit die Exits voneinander getrennt.

### Welches Timeout sollte ich in Node.js setzen?

Setzen Sie immer eines: `AbortSignal.timeout(30000)` für fetch, `timeout: 30000` für axios, `timeout: { request: 30000 }` für got. Dreißig Sekunden eignen sich für HTML-Seiten; geben Sie langsamen Zielen und mobilen Exits bis zu 60 Sekunden, und wiederholen Sie einmal mit einer neuen Verbindung, statt länger zu warten.

**Verbinden Sie Ihren Node.js Crawler** 5,94 $ für 10 GB, 0,50 $/GB von 50 GB. [Preise ansehen](https://crawlrelay.com/de/pricing/) · [Puppeteer Anleitung](https://crawlrelay.com/de/docs/puppeteer/)

---

CrawlRelay: CrawlRelay ist ein entwicklerfreundlicher rotierender Residential-Proxy- und 4G/5G mobile Proxy-Service für Scraper und KI-Datenpipelines: nicht verfallende Pay-as-you-go-Traffic ab 0,50 $/GB, mit Krypto bezahlt, ohne ID-Upload. Kein KYC — keine ID, kein Selfie, keine Dokumente. Mit Krypto bezahlen.
