{"library":"socks5-client","title":"SOCKS5 Client for Node.js","type":"library","description":"This package provides a low-level, unopinionated SOCKS v5 client socket implementation specifically designed for Node.js. It allows developers to proxy raw TCP connections through a SOCKSv5 server by wrapping a standard `net.Socket` and performing the SOCKSv5 handshake. First published in 2012 and last updated seven years ago (version 1.2.8), its release cadence is effectively abandoned, although the package remains available and functional for its specific niche. It serves as a foundational component for other packages like `socks5-http-client` and `socks5-https-client`. Unlike more modern SOCKS client libraries, `socks5-client` focuses solely on the SOCKSv5 protocol, operates synchronously, and does not include modern JavaScript features like Promises or built-in TypeScript definitions. Its key differentiator is its minimalist approach, providing direct control over the underlying socket stream for advanced use cases.","language":"javascript","status":"maintenance","last_verified":"Tue Apr 21","install":{"commands":["npm install socks5-client"],"cli":null},"imports":["const SocksClient = require('socks5-client');","const client = new SocksClient(options);","client.connect(port, host, callback);"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/mattcg/socks5-client","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/socks5-client","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const net = require('net');\nconst SocksClient = require('socks5-client');\n\nconst PROXY_HOST = process.env.SOCKS5_PROXY_HOST || '127.0.0.1';\nconst PROXY_PORT = parseInt(process.env.SOCKS5_PROXY_PORT || '1080', 10);\nconst TARGET_HOST = 'example.com';\nconst TARGET_PORT = 80;\n\n// Create a raw TCP socket to connect to the SOCKS5 proxy\nconst proxySocket = net.connect(PROXY_PORT, PROXY_HOST, () => {\n  console.log(`Connected to SOCKS5 proxy at ${PROXY_HOST}:${PROXY_PORT}`);\n\n  // Instantiate SocksClient with the proxy connection\n  const socksClient = new SocksClient();\n\n  // Initiate the SOCKS5 handshake to connect to the target host\n  socksClient.connect(\n    TARGET_PORT,\n    TARGET_HOST,\n    // Optional: add 'socksUsername', 'socksPassword' to options for auth\n    // { socksUsername: 'user', socksPassword: 'pass' },\n    proxySocket, // Pass the connected proxySocket\n    (err, destinationSocket) => {\n      if (err) {\n        console.error('SOCKS5 connection failed:', err.message);\n        proxySocket.end();\n        return;\n      }\n      console.log(`Successfully connected to ${TARGET_HOST}:${TARGET_PORT} via SOCKS5 proxy.`);\n\n      // Now destinationSocket is the proxied socket, ready for application data\n      const request = [\n        'GET / HTTP/1.1',\n        `Host: ${TARGET_HOST}`,\n        'Connection: close',\n        '',\n        ''\n      ].join('\\r\\n');\n\n      destinationSocket.write(request);\n\n      destinationSocket.on('data', (data) => {\n        console.log('Received data from target:', data.toString().substring(0, 200) + '...');\n      });\n\n      destinationSocket.on('end', () => {\n        console.log('Target connection ended.');\n        proxySocket.end();\n      });\n\n      destinationSocket.on('error', (data) => {\n        console.error('Target socket error:', data.message);\n        proxySocket.end();\n      });\n    }\n  );\n});\n\nproxySocket.on('error', (err) => {\n  console.error('Proxy socket error:', err.message);\n});\n","lang":"javascript","description":"This example demonstrates how to establish a SOCKSv5 proxied TCP connection to `example.com` on port 80. It first connects a raw `net.Socket` to the SOCKS5 proxy, then uses `socks5-client` to perform the SOCKS5 handshake and obtain a `destinationSocket` which is then used to send an HTTP GET request to the target host.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}