Nodejs Socks Proxy

HTTP Rotating & Static

  • 40 million IPs for all purposes
  • 195+ locations
  • 3 day moneyback guarantee

Visit smartproxy.com

socks-proxy-agent – npm

socks-proxy-agent6. 1. 0 • Public • Published a month ago Readme Explore BETA3 Dependencies254 Dependents20 Versions
A SOCKS proxy implementation for HTTP and HTTPS
This module provides an implementation that connects to a
specified SOCKS proxy server, and can be used with the built-in
and 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.
Installation
Install with npm:
$ npm install socks-proxy-agent
Examples
TypeScript example
import from ”;
import { SocksProxyAgent} from ‘socks-proxy-agent’;
const info = {
host: ”,
userId: ”,
password: ‘abcdef12345124’};
const agent = new SocksProxyAgent(info);
(”, { agent}, (res) => {
(res. headers);
();});
module example
var url = require(‘url’);
var = require(”);
var SocksProxyAgent = require(‘socks-proxy-agent’);
// SOCKS proxy to connect to
var proxy = || ‘socks127. 0. 1:1080’;
(‘using proxy server%j’, proxy);
// HTTP endpoint for the proxy to connect to
var endpoint = [2] || ”;
(‘attempting to GET%j’, endpoint);
var opts = (endpoint);
// create an instance of the `SocksProxyAgent` class with the proxy server information
var agent = new SocksProxyAgent(proxy);
= agent;
(opts, function (res) {
(‘”response” event! ‘, res. headers);
ws WebSocket connection example
var WebSocket = require(‘ws’);
// WebSocket endpoint for the proxy to connect to
var endpoint = [2] || ‘ws’;
(‘attempting to connect to WebSocket%j’, endpoint);
// initiate the WebSocket connection
var socket = new WebSocket(endpoint, { agent: agent});
(‘open’, function () {
(‘”open” event! ‘);
(‘hello world’);});
(‘message’, function (data, flags) {
(‘”message” event! %j%j’, data, flags);
License
(The MIT License)
Copyright (c) 2013 Nathan Rajlich <>
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.
Using a socks proxy to make requests in Node.js - Medium

HTTP Rotating & Static

  • 40 million IPs for all purposes
  • 195+ locations
  • 3 day moneyback guarantee

Visit smartproxy.com

Using a socks proxy to make requests in Node.js – Medium

If you have to make a requests through a proxy (for example, to get through a corporate firewall or to have your traffic appear as a specific IP address) socks is by far the best approach. Surprisingly, there’s not a lot of documentation on how to accomplish this, but it’s actually quite easy. I use axios to make server to server requests in It’s promise-based API is by far the easiest to deal with. Using the package socks-proxy-agent, we are able to replace axios’ default Agent to achieve our desired be begin, download your dependencies:npm install axios socks-proxy-agentThen, where you’re going to need to make requests, import your dependencies and instantiate them with the correct configuration:const axios = require(‘axios’);const SocksProxyAgent = require(‘socks-proxy-agent’);// replace with your proxy’s hostname and portconst proxyHost = REPLACE_ME, proxyPort = REPLACE_ME;// the full socks5 addressconst proxyOptions = `socks5${proxyHost}:${proxyPort}`;// create the socksAgent for axiosconst Agent = new SocksProxyAgent(proxyOptions);// the baseUrl for the api you are going to hitconst baseUrl = ”// create a new axios instanceconst client = ({baseUrl, Agent});Then, it’s just a matter of making your request:const googlePage = (‘/’)(res =>);
Doing http requests through a SOCKS5 proxy in NodeJS

Doing http requests through a SOCKS5 proxy in NodeJS

I’m planning to do a series of HTTP requests in NodeJS though Tor.
Tor uses SOCKS5 so I went out and searched for a way to proxify HTTP requests in NodeJS.
I’m planning to the the default quest() function to do the work. However, I can’t seem to find a way to use a proxy with that. Someone suggested that I could do this:
var = require(“”);
var options = {
host: “localhost”,
port: 9050,
path: “,
method: ‘GET’,
headers: {
Host: “, }};
var req = quest(options, function(res) {
(‘data’, function (chunk) {
(‘BODY: ‘ + chunk);});});
But it didn’t work.
So, any suggestions?
asked Jul 17 ’12 at 20:13
I’ve just published two modules that should help you do this: socks5–client and socks5–client.
Just use those instead of the default module. The API is the same. For example:
require(‘socks5–client’). request(options, function(res) {
(‘STATUS: ‘ + atusCode);
(‘HEADERS: ‘ + ringify(res. headers));
tEncoding(‘utf8’);
answered Mar 5 ’13 at 1:33
MatthewMatthew14. 3k2 gold badges35 silver badges28 bronze badges
3
I know I’m answering an old question but there is a better solution available for this question, about how to use sock4 & sock5 proxy in For the sake of simplicity, I will be using request-promise module however you can also use bare request module.
Requrement: socks-proxy-agent, request-promise
Example:
async function main() {
var proxy = “socks41. 2. 3. 4:35618″
var agent = new SocksProxyAgent(proxy);
uri: ‘targetUrl’,
agent: agent,
‘User-Agent’: ‘Request-Promise’}}
try {
var responce = await rp(options)} catch(err) {
(err)}
(responce)}
answered Feb 17 ’18 at 12:35
Not a complete answer, but you may want to keep your eye on these two modules.
Support is being added into:
I sent him an email asking when he expected this to be complete, will update this post soon with that information.
answered Aug 14 ’12 at 20:32
HortinsteinHortinstein2, 53720 silver badges21 bronze badges
I had the same problem and used polipo as proxy between node and TOR
node (request) – polilp roxy:8123 – polipo – tor (socks5:9050).
For mac (osx with brew) it worked like this:
brew install polipo tor
tor # start top
polipo socksParentProxy=localhost:9050 # start polipo
Working example with request
var request = require(‘request’);
var options = {‘url’:”, ‘proxy’:’localhost:8123′}
request(options,
function (error, response, body) {
if (error){
(error);
return;}
var usingTor = (dexOf(‘Congratulations. This browser is configured to use Tor. ‘)! == -1);
expect(usingTor)(true);});
answered Sep 14 ’16 at 9:25
Simon FakirSimon Fakir1, 54116 silver badges20 bronze badges
1
If you’re on *nix machine, you can use tsocks. It will “socksify” the whole process so you can use it even for anything which does not support proxies at all. This article has some great examples
Basically it’s as easy as doing tsocks node I am not sure if it works with tsocks npm start but you could give it a try (npm starts your code as a subprocess)
All you need is some setup first (put server = 127. 0. 1 to etc/)
answered Jul 17 ’18 at 7:40
Kamil TomšíkKamil Tomšík2, 3482 gold badges26 silver badges32 bronze badges
answered Jul 22 ’15 at 5:35
TimTim5451 gold badge5 silver badges14 bronze badges
Not the answer you’re looking for? Browse other questions tagged proxy tor or ask your own question.

Frequently Asked Questions about nodejs socks proxy

Leave a Reply

Your email address will not be published.