What is socks-proxy-agent?
The socks-proxy-agent package is a SOCKS proxy http.Agent implementation for HTTP and HTTPS. This package allows you to route HTTP and HTTPS requests through a SOCKS proxy server. It is useful for bypassing network restrictions or connecting to servers anonymously.
What are socks-proxy-agent's main functionalities?
HTTP/HTTPS request via SOCKS proxy
This code sample demonstrates how to send an HTTP or HTTPS request through a SOCKS proxy using the socks-proxy-agent package. The agent is created with the proxy server information and passed to the HTTP request options.
const SocksProxyAgent = require('socks-proxy-agent');
const agent = new SocksProxyAgent('socks://localhost:1080');
const https = require('https');
https.get('https://example.com', { agent }, (res) => {
console.log(`Got response: ${res.statusCode}`);
// consume response body
res.resume();
}).on('error', (e) => {
console.error(`Got error: ${e.message}`);
});
Other packages similar to socks-proxy-agent
http-proxy-agent
The http-proxy-agent package provides an http.Agent implementation that connects to a specified HTTP proxy server, and can be used for forwarding HTTP requests. Unlike socks-proxy-agent, it does not support SOCKS proxies, only HTTP.
https-proxy-agent
Similar to http-proxy-agent, https-proxy-agent provides an http.Agent implementation for HTTPS requests that connects to an HTTPS proxy server. It is specifically designed for HTTPS connections and does not support SOCKS proxies.
proxy-agent
The proxy-agent package is a more general solution that supports multiple proxy protocols including HTTP, HTTPS, SOCKS, and PAC files. It can be used as a drop-in replacement for the standard http.Agent and automatically selects the appropriate agent based on the proxy's protocol. This makes it more versatile than socks-proxy-agent, which is specialized for SOCKS proxies only.
socks-proxy-agent
A SOCKS proxy http.Agent
implementation for HTTP and HTTPS
This module provides an http.Agent
implementation that connects to a
specified SOCKS proxy server, and can be used with the built-in http
and https
modules.
It can also be used in conjunction with the ws
module to establish a WebSocket
connection over a SOCKS proxy. See the "Examples" section below.
Examples
import https from 'https';
import { SocksProxyAgent } from 'socks-proxy-agent';
const agent = new SocksProxyAgent(
'socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com'
);
https.get('https://ipinfo.io', { agent }, (res) => {
console.log(res.headers);
res.pipe(process.stdout);
});
ws
WebSocket connection example
import WebSocket from 'ws';
import { SocksProxyAgent } from 'socks-proxy-agent';
const agent = new SocksProxyAgent(
'socks://your-name%40gmail.com:abcdef12345124@br41.nordvpn.com'
);
var socket = new WebSocket('ws://echo.websocket.events', { agent });
socket.on('open', function () {
console.log('"open" event!');
socket.send('hello world');
});
socket.on('message', function (data, flags) {
console.log('"message" event! %j %j', data, flags);
socket.close();
});
License
(The MIT License)
Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.