SOCKS5 HTTP Client for Node.js

raw JSON →
1.0.4 verified Thu Apr 23 auth: no javascript abandoned

This package provides a SOCKS v5 HTTP client implementation specifically for Node.js environments. It enables making HTTP requests through a SOCKS5 proxy, commonly used for anonymizing traffic via services like Tor. The current stable version is 1.0.4, last published over eight years ago (July 2018). The library focuses solely on HTTP, explicitly directing users to a separate `socks5-https-client` package for HTTPS. Its primary differentiators were its straightforward integration with the deprecated `request` library and its direct support for SOCKS5 proxying, including authentication. Due to its age and lack of updates, it is largely incompatible with modern Node.js versions and lacks contemporary features like Promise-based APIs.

error Error: Cannot find module 'socks5-client'
cause The core dependency `socks5-client` was not installed correctly or Node.js cannot resolve its path.
fix
Ensure npm install has been run in your project root, or check your NODE_PATH environment variable if using global modules. This can also indicate issues with older Node.js versions.
error TypeError: Cannot set property 'flowing' of undefined
cause This error often occurs in older stream implementations (like those in this package) when interacting with newer Node.js stream APIs or versions where internal stream properties have changed.
fix
This package is not compatible with modern Node.js versions (specifically, likely >14.17.0). Downgrade Node.js or, preferably, migrate to a current, maintained SOCKS5 client library.
error RequestError: Error:connect ETIMEDOUT occurred with some socks5 server
cause The client could not establish a connection to the specified SOCKS5 proxy server, usually due to incorrect `socksHost`/`socksPort` settings, the proxy server not running, or network firewall rules.
fix
Verify that socksHost and socksPort are correct. Ensure the SOCKS5 proxy is running and accessible from the machine running the Node.js application. Check firewall rules.
error Broken for node version above 14.17.0
cause Internal compatibility issues with Node.js changes post-14.17.0, likely related to networking or stream APIs.
fix
This package is abandoned and incompatible with recent Node.js versions. Upgrade to a modern, actively maintained SOCKS proxy agent (e.g., https-proxy-agent or socks-proxy-agent).
breaking The package is severely unmaintained, with the last publish over eight years ago. It is known to be broken for Node.js versions above 14.17.0 due to internal compatibility issues, making it unsuitable for modern Node.js applications.
fix Migrate to a actively maintained SOCKS5 client library for Node.js, such as `socks-proxy-agent` or explore `node-fetch` with a custom agent.
security Being an unmaintained SOCKS5 client, this package may contain unpatched security vulnerabilities. SOCKS5 implementations have been susceptible to heap buffer overflows (e.g., CVE-2023-38545 in curl) and other issues. Using this library in production is a significant security risk.
fix Do not use this package for new projects or in security-sensitive environments. Replace with a well-maintained and audited SOCKS5 client.
gotcha This client explicitly supports only HTTP requests, not HTTPS. For HTTPS traffic over SOCKS5, the separate `socks5-https-client` package (also unmaintained) or a modern alternative is required.
fix For HTTPS, you must use a different library. If you need a combined solution, look for more comprehensive proxy agents.
deprecated The recommended integration path for `socks5-http-client` involves passing its `Agent` to the `request` library, which itself was fully deprecated in February 2020. This indicates an outdated ecosystem reliance.
fix Avoid integrating with the deprecated `request` library. If using this package, use it directly with Node's native `http` module or choose a modern HTTP client with SOCKS support.
gotcha This package is written exclusively in CommonJS (CJS) and does not support ES module (ESM) import syntax (`import ... from '...'`). Attempting to use ESM imports will lead to runtime errors in modern Node.js environments.
fix Stick to `require()` syntax for importing this package. For modern applications, consider libraries that offer native ESM support.
npm install socks5-http-client
yarn add socks5-http-client
pnpm add socks5-http-client

This example demonstrates how to make a basic HTTP GET request through a SOCKS5 proxy configured via environment variables, logging the initial part of the response body.

const shttp = require('socks5-http-client');

const SOCKS_HOST = process.env.SOCKS_HOST ?? 'localhost';
const SOCKS_PORT = parseInt(process.env.SOCKS_PORT ?? '1080', 10);

shttp.get({
  hostname: 'www.example.com',
  path: '/',
  socksHost: SOCKS_HOST,
  socksPort: SOCKS_PORT,
  // Optional SOCKS5 authentication
  // socksUsername: process.env.SOCKS_USERNAME,
  // socksPassword: process.env.SOCKS_PASSWORD,
}, function(res) {
  res.setEncoding('utf8');
  let data = '';
  res.on('data', function(chunk) {
    data += chunk;
  });
  res.on('end', function() {
    console.log('Received response:');
    console.log(data.substring(0, 200) + '...'); // Log first 200 chars
  });
}).on('error', (e) => {
  console.error(`Request failed: ${e.message}`);
});