npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

proxyratemanager

v1.0.1

Published

ES6 JS classes for http/https Proxy Requests and IP rate limiting

Downloads

3

Readme

proxyratemanager

ES6 JS classes for http/https Proxy Requests and IP rate limiting

Installation

npm install proxyratemanager --save

Usage

This is a module to facilitate proxying requests while staying within specified rate limits per action.

NOTE: This module heavily relies on AdvancedRequest. Good understanding of it is pretty important to use this.

Main features:

  • Automatically launch tor and change exit node
  • Specification of multiple circuits through proxies or tor
  • Automatic circuit "health" management to help avoid circuits during their downtime
  • Specify actions to be limited by name per IP per unit time
  • Specify pool of proxies to be randomly or specifically used

Example setup

const {ProxyRateManager, AdvancedProxiedRequest} = require('proxyratemanager');

let proxyRateManager = new ProxyRateManager({
  EXTERNAL_IP_CHECK_URL: `https://www.myexternalip.com/raw`,
});

let oneDayInMs = 1000 * 60 * 60 * 24;
proxyRateManager.addRateLimitActionKey({key: "apirequest1", limit: 1200, timeForRateReset: oneDayInMs});
proxyRateManager.addRateLimitActionKey({key: "apirequest2", limit: 1200, timeForRateReset: oneDayInMs});

await proxyRateManager.initWithCircuits([
  // named socks5h proxy
  {
    "name": "login_proxy", "port":7777,"username":"root","password":"pwpwpw","host":"example.com",
    addToCyclingCircuitPool: false, // (won't be included in pool)
  },

  // http proxy (will be in proxy pool)
  {"type": "http", "port":7777,"username":"root","password":"pwpwpw","host":"example2.com"},

  // isLocalTor being true for ANY circuit will trigger ProxyRateManager to start up tor
  // and manage it, killing it or sending signals to it to switch exit node IP addresses. 
  {"isLocalTor": true, "port":9050,"host":"3.3.3.3"},

  // unnamed socks5h proxies (in proxy pool)
  {"port":7777,"username":"root","password":"pwpwpw","host":"1.1.1.1"},
  {"port":7777,"username":"root","password":"pwpwpw","host":"2.2.2.2"},
  {"port":7777,"host":"3.3.3.3"}, // no un/pw
]);

// unnamed socks5h proxies (in proxy pool)
proxyRateManager.addCircuit({"port":7777,"username":"root","password":"pwpwpw","host":"4.4.4.4"});

Create a ProxyClient to send requests using the pool for this manager

let proxyClient = proxyRateManager.createClient();

// Send a request through this proxyClient
let req = new AdvancedProxiedRequest({
  url: `http://example.com/api/v1/dosomething`,
  method: 'GET',
  name: "apirequest1", // used to signal an action completed
  reqArgs: {
    proxyClient: proxyClient // specify this client to use
  },
});


// Call before running request on for this action name of "apirequest1"
await proxyClient.changeIPIfNecessary("apirequest1");

let jsonData = await req.runAsync(); // run the request (through the proxy)

if (jsonData.something_is_wrong_with_request_results) {
  // call .forceIPChangeImmediately() to have your exit IP randomly changed (guaranteed to change)
  await proxyClient.forceIPChangeImmediately();
} else {
  // report action completed for counters to update
  proxyClient.reportNewAction("apirequest1");
}

Get details about current circuit for this client object

let exitIP = proxyClient.getCurrentIP(); // get the current external/exit IP from the client
let circuitIdentifier = proxyClient.circuit.getIdentifier(); // get the information its the circuit in use
let health = proxyClient.circuit.getHealth(); // All proxies are periodically polled to check their health/IPs

console.log(`[D] proxyClient details: exitIP=${exitIP} circuitIdentifier=${circuitIdentifier} health=${health}`);

A lot goes into this module. Reading the code is useful to understand more of how it works.

Credits

http://x64projects.tk/