SOCKS Proxy HTTP/HTTPS Agent

10.0.0 · active · verified Tue Apr 21

socks-proxy-agent is a Node.js module that provides an `http.Agent` implementation, enabling HTTP and HTTPS requests, and WebSocket connections, to be routed through a SOCKS proxy server. It supports SOCKS4, SOCKS4a, SOCKS5, and SOCKS5h protocols, offering flexibility in how connections are established and resolved. The current stable version is 10.0.0. The package is part of the broader `proxy-agents` monorepo by TooTallNate, which implies a release cadence often synchronized with its core dependency `agent-base` and Node.js LTS updates, as evidenced by the recent major version bump due to an increased minimum Node.js requirement. Its key differentiator is its focused and robust implementation for SOCKS proxies, making it suitable for scenarios requiring specific proxy tunneling capabilities for anonymity, bypassing geo-restrictions, or internal network access.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create a `SocksProxyAgent` instance and use it with Node.js's built-in `https` module to route an HTTPS request through a SOCKS proxy, including basic error handling.

import https from 'https';
import { SocksProxyAgent } from 'socks-proxy-agent';

// Replace with your SOCKS proxy URI, including optional authentication
// Example with username/password: 'socks://user%40example.com:password@proxy.example.com:1080'
const SOCKS_PROXY_URI = process.env.SOCKS_PROXY_URI ?? 'socks://127.0.0.1:1080';

// Create a new SocksProxyAgent instance
const agent = new SocksProxyAgent(SOCKS_PROXY_URI);

console.log(`Making HTTPS request through SOCKS proxy: ${SOCKS_PROXY_URI}`);

https.get('https://ipinfo.io/json', { agent }, (res) => {
  console.log(`Response Status: ${res.statusCode}`);
  console.log('Response Headers:', res.headers);

  let data = '';
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    console.log('Response Body:');
    try {
      const json = JSON.parse(data);
      console.log(json);
    } catch (e) {
      console.error('Failed to parse JSON response:', e);
      console.log(data);
    }
  });
}).on('error', (err) => {
  console.error('Error making HTTPS request:', err.message);
});

view raw JSON →