SOCKS5 HTTPS Client for Node.js
This library provides a SOCKSv5 client specifically for making HTTPS requests within Node.js environments. It enables routing secure web traffic through a SOCKSv5 proxy, such as a local Tor instance. The package, currently at version 1.2.1, saw its last release in 2013 and is not actively maintained, which raises concerns about its compatibility with modern Node.js versions, updated security protocols, and potential vulnerabilities. It differentiates itself by focusing exclusively on HTTPS, requiring the separate `socks5-http-client` package for plain HTTP requests. Its primary utility has been for applications requiring anonymous or proxied HTTPS communication, though its abandoned status means developers should exercise caution. Due to its inactivity, there is no regular release cadence.
Common errors
-
ReferenceError: require is not defined
cause Attempting to use `require()` in an ES Module context.fixEnsure your file is treated as CommonJS (e.g., `.js` file without `"type": "module"` in `package.json`, or explicitly `.cjs` extension) or use a modern, ESM-compatible SOCKS proxy client. -
TypeError: shttps.get is not a function
cause Incorrect import of the `shttps` object when attempting an ES Module import.fixThis package exports a default CommonJS module. Use `const shttps = require('socks5-https-client');` instead of `import shttps from 'socks5-https-client';`. -
Error: self-signed certificate in certificate chain
cause The HTTPS server uses a self-signed or untrusted certificate, and `rejectUnauthorized` is true (the default).fixFor testing or specific scenarios, set `rejectUnauthorized: false` in the options. For production, ensure the SOCKS proxy is correctly configured or the target server has a trusted certificate.
Warnings
- breaking This package is CommonJS-only and does not support ES Modules natively. Attempting to `import` it will result in errors in modern Node.js ESM environments.
- gotcha The package is effectively abandoned, with the last release in 2013 and no recent maintenance. This means it may not be compatible with newer Node.js versions (e.g., >v16, >v18), recent OpenSSL changes, or security best practices.
- gotcha This library only supports HTTPS requests. For plain HTTP requests through SOCKSv5, a separate package `socks5-http-client` from the same author is required.
- gotcha Node.js engine requirement is `>= 6.4.0`. While it might run on newer versions, its lack of updates means it has not been tested or optimized for changes in Node.js runtime, especially concerning networking or TLS.
Install
-
npm install socks5-https-client -
yarn add socks5-https-client -
pnpm add socks5-https-client
Imports
- shttps
import shttps from 'socks5-https-client';
const shttps = require('socks5-https-client'); - Agent
import { Agent } from 'socks5-https-client/lib/Agent';const Agent = require('socks5-https-client/lib/Agent'); - get
import { get } from 'socks5-https-client';const shttps = require('socks5-https-client'); shttps.get(...);
Quickstart
const shttps = require('socks5-https-client');
shttps.get({
hostname: 'encrypted.google.com',
path: '/',
rejectUnauthorized: true, // This is the default.
socksHost: 'localhost',
socksPort: 1080 // Default SOCKS port
}, function(res) {
res.setEncoding('utf8');
res.on('readable', function() {
process.stdout.write(res.read()); // Log response to console.
});
res.on('end', () => {
console.log('\nHTTPS request through SOCKS5 completed.');
});
res.on('error', (err) => {
console.error('Response error:', err.message);
});
}).on('error', (err) => {
console.error('Request error:', err.message);
});