Usa Shifter con Node.js
Añade los proxies residenciales y de ISP de Shifter a cualquier proyecto de Node.js en minutos. Funciona perfectamente con axios, el fetch nativo (Node 18+), got, undici, Puppeteer y Playwright.
Inicio rápido
Instalar
npm install axios https-proxy-agent Uso básico
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
const proxyUrl =
"customer-USERNAME-country-us-sid-123ABC:PASSWORD@p.shifter.io:443";
const agent = new HttpsProxyAgent(proxyUrl);
const { data } = await axios.get("https://ipinfo.io/json", {
httpsAgent: agent,
proxy: false,
});
console.log(data);
// { ip: "154.16.xxx.xxx", city: "New York", country: "US", ... } Características
Ejemplos
axios + sesión sticky con geolocalización
Fija una IP residencial para toda una sesión de usuario añadiendo un `sid` al nombre de usuario. Añade `country-uk`, `city-london` o `asn-7922` para segmentar geográficamente.
import axios from "axios";
import { HttpsProxyAgent } from "https-proxy-agent";
import { randomBytes } from "node:crypto";
const sid = randomBytes(4).toString("hex");
const proxyUrl =
`customer-USERNAME-country-uk-city-london-sid-${sid}-ttl-300:` +
`PASSWORD@p.shifter.io:443`;
const client = axios.create({
httpsAgent: new HttpsProxyAgent(proxyUrl),
proxy: false,
timeout: 30_000,
headers: {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
},
});
const login = await client.post("https://example.com/login", {
email: "user@example.com",
password: "secret",
});
const dashboard = await client.get("https://example.com/dashboard");
const orders = await client.get("https://example.com/orders");
console.log(login.status, dashboard.status, orders.status); fetch nativo (Node 18+) con undici
Si usas Node 18 o superior, no necesitas axios: utiliza el fetch global con un ProxyAgent de undici. La huella mínima posible.
import { ProxyAgent, setGlobalDispatcher } from "undici";
const proxyAgent = new ProxyAgent({
uri: "http://p.shifter.io:443",
token: `Basic ${Buffer.from(
"customer-USERNAME-country-us-sid-456DEF:PASSWORD",
).toString("base64")}`,
});
setGlobalDispatcher(proxyAgent);
const r = await fetch("https://api.example.com/products?page=1");
const json = await r.json();
console.log(json); Puppeteer con proxy autenticado
Enruta Chromium a través de Shifter y autentícate mediante page.authenticate(). Combina `sid` con cookies a nivel de navegador para mantener una sesión estable durante todo el rastreo.
import puppeteer from "puppeteer";
const PROXY_HOST = "p.shifter.io";
const PROXY_PORT = 443;
const PROXY_USER = "customer-USERNAME-country-de-sid-789GHI";
const PROXY_PASS = "PASSWORD";
const browser = await puppeteer.launch({
args: [`--proxy-server=http://${PROXY_HOST}:${PROXY_PORT}`],
headless: "new",
});
const page = await browser.newPage();
await page.authenticate({ username: PROXY_USER, password: PROXY_PASS });
await page.setUserAgent(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
);
await page.goto("https://example.com", { waitUntil: "networkidle0" });
const title = await page.title();
const html = await page.content();
console.log(title, html.length, "bytes");
await browser.close(); Playwright (multinavegador)
Las opciones de lanzamiento de Playwright aceptan proxies de forma nativa, con credenciales en línea. La misma configuración funciona para Chromium, Firefox y WebKit.
import { chromium } from "playwright";
const browser = await chromium.launch({
proxy: {
server: "http://p.shifter.io:443",
username: "customer-USERNAME-country-fr-city-paris-sid-ABC123",
password: "PASSWORD",
},
});
const context = await browser.newContext({
userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
});
const page = await context.newPage();
await page.goto("https://example.com");
const headlines = await page.locator(".headline").allTextContents();
console.log(headlines);
await browser.close(); Preguntas frecuentes
Preguntas frecuentes sobre el uso de Shifter con Node.js.
Pasa un https-proxy-agent (o http-proxy-agent para HTTP sin cifrar) en la opción httpsAgent, y establece proxy: false para que axios use el agente directamente. El formato de la URL del proxy es `http://USER:PASS@p.shifter.io:443`. La misma instancia de axios puede reutilizarse entre solicitudes.
Empieza a usar Shifter con Node.js
Añade los más de 205M de proxies residenciales y de ISP de Shifter a tu stack de Node.js en menos de 5 minutos. Rotación por solicitud, sesiones sticky y soporte completo para Puppeteer / Playwright.