Node.js und TypeScript
Leiten Sie Anfragen in Node.js und TypeScript mit undici, axios, nativem fetch oder SOCKS5 über Ihre dedizierte statische IPv4 mit Connection-Pooling.
Auf dieser Seite8
Welcher Client passt, hängt vom Proxy-Protokoll und Ihrer Node.js-Laufzeit ab – wählen Sie das Muster für Ihren Stack:
| Client | Proxy-Schemata | Ideal für |
|---|---|---|
undici (ProxyAgent) |
https://, http:// |
Standardwahl für Node-20+-Server und Serverless-Funktionen mit fetch |
axios + https-proxy-agent |
https://, http:// |
Bestehende axios-Codebasen |
Natives fetch + NODE_USE_ENV_PROXY=1 |
https://, http:// |
Ohne zusätzliche Pakete ab Node 22.21+ und Node 24+ |
socks-proxy-agent |
socks5h:// |
node:https- oder axios-Clients, die SOCKS5 brauchen |
Schritt 1. Proxy-URL abrufen
- Öffnen Sie IP-Adressen in Ihrem Prontaro-Dashboard (my.prontaro.com/ips) und wählen Sie Ihre dedizierte IPv4.
- Kopieren Sie die
HTTPS-Proxy-URL (:443) unter Proxy-Zugangsdaten.
Exportieren Sie die Proxy-URL als PRONTARO_PROXY_URL:
export PRONTARO_PROXY_URL="https://user:pass@<entry>.prontaro.io:443"undici (ProxyAgent) – empfohlen
Installieren Sie undici und legen Sie einen modulweiten ProxyAgent an, damit alle Anfragen denselben TCP-/TLS-Keep-Alive-Pool teilen:
npm install undici// egress-client.ts
import { fetch, ProxyAgent } from 'undici';
const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
throw new Error('PRONTARO_PROXY_URL is not set');
}
// Ein gemeinsamer Agent pro Prozess – nicht nach jeder Anfrage schließen
export const proxyAgent = new ProxyAgent({
uri: proxyUrl,
connections: 10,
});
export async function checkOutboundIp(): Promise<string> {
const res = await fetch('https://api.ipify.org', {
dispatcher: proxyAgent,
signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
return (await res.text()).trim();
}
// Nur beim sauberen Beenden des Prozesses schließen
process.once('SIGTERM', () => {
void proxyAgent.close();
});
console.log(await checkOutboundIp());Prüfen Sie Ihre ausgehende IP:
npx tsx egress-client.ts
203.0.113.10Sobald api.ipify.org Ihre dedizierte IPv4 zurückgibt, können Sie Ziele im Dashboard (IP-Adressen → Proxy-Zugangsdaten → Zugriff) einschränken.
axios + https-proxy-agent
Die integrierte proxy-Option von Axios hat Schwierigkeiten mit https://-Proxy-Hosts und kann mit Umgebungsvariablen kollidieren. Übergeben Sie HttpsProxyAgent als httpsAgent und setzen Sie explizit proxy: false:
npm install axios https-proxy-agent// axios-client.ts
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
const proxyUrl = process.env.PRONTARO_PROXY_URL;
if (!proxyUrl) {
throw new Error('PRONTARO_PROXY_URL is not set');
}
const httpsAgent = new HttpsProxyAgent(proxyUrl);
export const partnerApi = axios.create({
httpsAgent,
proxy: false, // integrierte HTTP_PROXY-Auswertung von Axios deaktivieren
timeout: 15_000,
});
const { data } = await partnerApi.get<string>('https://api.ipify.org');
console.log(data.trim());Natives fetch mit NODE_USE_ENV_PROXY=1 (Node 22 / 24)
Ab Node.js 24+ und Node.js 22.21+ wertet das eingebaute fetch() HTTPS_PROXY, HTTP_PROXY und NO_PROXY ohne Zusatzpakete aus, wenn Sie Node mit NODE_USE_ENV_PROXY=1 (oder --use-env-proxy) starten:
// check-env.mjs
const res = await fetch('https://api.ipify.org', {
signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
console.log((await res.text()).trim());HTTPS_PROXY="$PRONTARO_PROXY_URL" \
NO_PROXY="localhost,127.0.0.1,::1,169.254.169.254,.internal" \
NODE_USE_ENV_PROXY=1 \
node check-env.mjsDa dies für jeden fetch()-Aufruf im Prozess gilt, setzen Sie immer NO_PROXY, damit interne Dienste und Telemetrie an Prontaro vorbeilaufen.
SOCKS5 (socks5h://) mit socks-proxy-agent
undici.ProxyAgent unterstützt nur http:// und https://. Für socks5h:// (:1080) kombinieren Sie SocksProxyAgent mit axios oder node:https:
npm install axios socks-proxy-agent// socks-client.ts
import axios from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';
// socks5h:// verwenden, damit DNS auf dem Prontaro-Server aufgelöst wird
const socksUrl = process.env.PRONTARO_SOCKS_URL; // socks5h://user:pass@<entry>.prontaro.io:1080
if (!socksUrl) {
throw new Error('PRONTARO_SOCKS_URL is not set');
}
const socksAgent = new SocksProxyAgent(socksUrl);
const { data } = await axios.get<string>('https://api.ipify.org', {
httpAgent: socksAgent,
httpsAgent: socksAgent,
proxy: false,
timeout: 15_000,
});
console.log(data.trim());Häufige Probleme mit Node.js
- Globales
fetchmit npm-undici-ProxyAgentmischen. Versionsunterschiede zwischen gebündeltem und installiertemundicibrechendispatcher. Importieren Sie beide aus'undici'. proxy: falseinaxiosvergessen. Ist zusätzlich zuhttpsAgentnochHTTPS_PROXYgesetzt, versucht Axios die Anfrage doppelt zu proxyn.SocksProxyAgentanfetch({ dispatcher })übergeben.SocksProxyAgentimplementiert Nodeshttp.Agent, nichtundici.Dispatcher.- Neuer Agent pro Anfrage.
new ProxyAgent(...)im Route-Handler erzwingt jedes Mal einen neuen Proxy-TLS-Handshake und erreicht das Limit gleichzeitiger Verbindungen pro IP.
API-Aufruf mit Relay-URL
In Edge-Runtimes oder Codebasen, in denen Sie keinen Proxy-Agent konfigurieren können, legen Sie im Dashboard (IP-Adressen) ein Relay an und rufen es direkt per fetch auf:
const res = await fetch(`${process.env.PRONTARO_RELAY_URL}/v1/status`, {
headers: {
Authorization: `Bearer ${process.env.PARTNER_API_TOKEN}`,
// Nur mitsenden, wenn ein Passwort gesetzt wurde (im Dashboard unter IP-Adressen → Relay-Adresse → Zugriff):
'Prontaro-Relay-Auth': `${process.env.RELAY_LOGIN}:${process.env.RELAY_PASSWORD}`,
},
signal: AbortSignal.timeout(15_000),
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
console.log(await res.json());Details zu TLS-Terminierung und Limits stehen unter Relay-Adressen.
Nächste Schritte
- curl und Umgebungsvariablen — Fehler
407und403mitcurl -vanalysieren. - HTTP- & SOCKS5-Proxy — Allowlists für
accessundtargetssowie Zugangsdaten-Rotation konfigurieren. - Statische IP für Vercel — Proxy- und Relay-Adressen in Vercel Functions einrichten.
- Statische IP für AWS Lambda — eine statische IP ohne VPC-Aufwand und ohne NAT Gateway nutzen.
Stimmt etwas auf dieser Seite nicht? Schreiben Sie uns