socks
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
ip | 2.0.1 | 15.13 kB | MIT | prod | |
smart-buffer | 4.2.0 | 21.03 kB | MIT | prod |
Socks is a fully-featured SOCKS proxy client that supports SOCKSv4, SOCKSv4a, and SOCKSv5. It includes Bind and Associate functionality, providing users with comprehensive proxy support. This tool is perfectly suited for Node.js development environments because it enables developers to create and control proxy connections via code, ultimately establishing secure data routes.
Using Socks involves setting up your environment with Node.js v10.0+ and installing the Socks package using either npm (npm install --save socks
) or yarn (yarn add socks
). Afterward, you can start using Socks in your JavaScript or TypeScript code by importing the Socks package. Here is an example of how to use it:
// import the SocksClient
const SocksClient = require('socks').SocksClient;
// define connection options
const options = {
proxy: {
host: '159.203.75.200', // ipv4 or ipv6 or hostname
port: 1080,
type: 5 // Proxy version (4 or 5)
},
command: 'connect', // SOCKS command (createConnection factory function only supports the connect command)
destination: {
host: '192.30.253.113', // github.com (hostname lookups are supported with SOCKS v4a and 5)
port: 80
}
};
// create connection
SocksClient.createConnection(options)
.then(info => {
console.log(info.socket);
// <Socket ...> (this is a raw net.Socket that is established to the destination host through the given proxy server)
})
.catch(err => {
// Handle errors
});
You can find the Socks documentation in the package's GitHub repository. The docs provide a detailed description of its features, usage examples for various scenarios (like creating a connection, chaining proxies, or using the TCP relay and UDP relay), and information on how to migrate from v1. They also include a comprehensive API reference and guidelines for handling errors.