Node.js Integration

Node.js Proxy SetupAxios, fetch, and got with mobile IPs

Configure SOCKS5 and HTTP proxies with popular Node.js HTTP clients. From Axios to native fetch, get your JavaScript apps running through mobile IPs.

Supported Libraries

  • Axios (most popular)
  • node-fetch / undici
  • got
  • Native http/https modules

Configuration Examples

1. Axios with SOCKS5

// npm install axios socks-proxy-agent
const axios = require('axios');
const { SocksProxyAgent } = require('socks-proxy-agent');

const agent = new SocksProxyAgent(
  'socks5://your_username:your_password@proxy.proxies.sx:10001'
);

const response = await axios.get('https://httpbin.org/ip', {
  httpAgent: agent,
  httpsAgent: agent
});

console.log(response.data);

2. Axios with HTTP Proxy

// npm install axios
const axios = require('axios');

const instance = axios.create({
  proxy: {
    protocol: 'http',
    host: 'proxy.proxies.sx',
    port: 10001,
    auth: {
      username: 'your_username',
      password: 'your_password'
    }
  }
});

const response = await instance.get('https://httpbin.org/ip');
console.log(response.data);

3. node-fetch with SOCKS5

// npm install node-fetch socks-proxy-agent
const fetch = require('node-fetch');
const { SocksProxyAgent } = require('socks-proxy-agent');

const agent = new SocksProxyAgent(
  'socks5://your_username:your_password@proxy.proxies.sx:10001'
);

const response = await fetch('https://httpbin.org/ip', { agent });
const data = await response.json();
console.log(data);

4. got with SOCKS5

// npm install got socks-proxy-agent
const got = require('got');
const { SocksProxyAgent } = require('socks-proxy-agent');

const agent = new SocksProxyAgent(
  'socks5://your_username:your_password@proxy.proxies.sx:10001'
);

const response = await got('https://httpbin.org/ip', {
  agent: {
    http: agent,
    https: agent
  }
}).json();

console.log(response);

5. https-proxy-agent

// npm install axios https-proxy-agent
const axios = require('axios');
const { HttpsProxyAgent } = require('https-proxy-agent');

const agent = new HttpsProxyAgent(
  'http://your_username:your_password@proxy.proxies.sx:10001'
);

const response = await axios.get('https://httpbin.org/ip', {
  httpsAgent: agent
});

console.log(response.data);

6. TypeScript Setup

import axios, { AxiosInstance } from 'axios';
import { SocksProxyAgent } from 'socks-proxy-agent';

interface ProxyConfig {
  host: string;
  port: number;
  username: string;
  password: string;
}

function createProxiedClient(proxy: ProxyConfig): AxiosInstance {
  const agent = new SocksProxyAgent(
    `socks5://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`
  );

  return axios.create({
    httpAgent: agent,
    httpsAgent: agent,
    timeout: 30000
  });
}

const client = createProxiedClient({
  host: 'proxy.proxies.sx',
  port: 10001,
  username: 'your_username',
  password: 'your_password'
});

const { data } = await client.get<{ origin: string }>('https://httpbin.org/ip');
console.log(data.origin);

7. Proxy Rotation

const axios = require('axios');
const { SocksProxyAgent } = require('socks-proxy-agent');

class ProxyRotator {
  constructor(ports, username, password) {
    this.ports = ports;
    this.username = username;
    this.password = password;
    this.currentIndex = 0;
  }

  getNextAgent() {
    const port = this.ports[this.currentIndex];
    this.currentIndex = (this.currentIndex + 1) % this.ports.length;

    return new SocksProxyAgent(
      `socks5://${this.username}:${this.password}@proxy.proxies.sx:${port}`
    );
  }

  async get(url) {
    const agent = this.getNextAgent();
    return axios.get(url, { httpAgent: agent, httpsAgent: agent });
  }
}

const rotator = new ProxyRotator(
  [10001, 10002, 10003, 10004, 10005],
  'your_username',
  'your_password'
);

// Each request uses a different proxy
for (let i = 0; i < 5; i++) {
  const { data } = await rotator.get('https://httpbin.org/ip');
  console.log(`Request ${i + 1}:`, data.origin);
}
Pro Tip: Always use socks-proxy-agent for SOCKS5 proxies. Native Axios proxy config only supports HTTP proxies.

Node.js Proxy Best Practices

Use Agent Libraries

socks-proxy-agent and https-proxy-agent work with any HTTP client. More flexible than library-specific proxy options.

Reuse Agents

Create agents once and reuse them. Creating new agents for each request adds unnecessary overhead.

Handle Errors

Proxy connections can fail. Use try/catch and implement retry logic with proxy rotation for reliability.

Set Timeouts

Always configure timeouts. Default is often too long or infinite. 30 seconds is a reasonable starting point.

Start Building with Node.js

Get mobile proxies for reliable HTTP requests.