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

proxyspace

v2.1.0

Published

API wrapper for ProxySpace

Downloads

5

Readme

ProxySpace Wrapper Docs

In this document you can look through and over the library reference. npm i proxyspace@latest

Examples

First let's start with some examples before going further deep.

Example 1

const { ProxySpaceV2 } = require("proxyspace");

var util = new ProxySpaceV2();
util.proxySpace.defaults.timeout = 10000;

util.Proxify("http", "array").then((proxyList) => {
  util.CheckProxy(proxyList, "http", (err, res) => {
    process.stdout.write(res);
  });
});

This will scrape HTTP proxies and check them. Every time a check is completed it calls up the callback you have given. It works in an in-memory enqueue for rapid checking with non blocking IO.

We can also define a functionality to the module, to use proxies while connecting to the ProxySpace API and so on. For that purpose we can define custom headers, proxy and timeout at class initialization level. You can later on, after the initialization any time manipulate it by <class>.proxySpace property. For example lets say we wanted to change/modify the proxy we can use the following property: <class>.proxySpace.defaults.proxy

Lets go deeper into that with an example

const { ProxySpaceV2 } = require("proxyspace");
const { ProxySpace_Countries } = require("proxyspace/dist/@types");

(async () => {
  var util = new ProxySpaceV2(
    {
      "cache-control": "no-store",
    },
    {
      auth: {
        username: "rvugmczm",
        password: "3j296ogi3b86",
      },
      host: "2.56.119.93",
      port: 5074,
      protocol: "http",
    }
  );
  util.proxySpace.defaults.timeout = 2000;

  let subnet = await util.IP_Rangify(ProxySpace_Countries.NL);
  subnet.net.forEach((sub) => {
    sub.ip.forEach((sub_ips) => {
      process.stdout.write(sub_ips + "\n");
    });
  });
  util.proxySpace.defaults.proxy = undefined; // do not use proxy anymore when sending requests to the ProxySpace end
})();

This will use the given proxy with the given AUTH at all requests to the ProxySpace API, if auth property was not defined it would use no authentication for the proxy server. What this code is doing is to get all IP ranges and then extract all IPs in the IP ranges.

We could also do something like:

const { ProxySpaceV2 } = require("proxyspace")(async () => {
  var util = new ProxySpaceV2(
    {
      "cache-control": "no-store",
    },
    {
      auth: {
        username: "rvugmczm",
        password: "3j296ogi3b86",
      },
      host: "2.56.119.93",
      port: 5074,
      protocol: "http",
    }
  );
  util.proxySpace.defaults.timeout = 2000;
  let geolocation = await util.GeoLocation("84.212.11.23");

  console.log(geolocation);
})();

// Output
/*{
  asn_number: 41164,
  asn_organization: 'Telia Norge AS',
  city: 'Kristiansand',
  country: 'Norway',
  country_code: 'NO',
  ip: '84.212.11.23',
  latitude: 58.1495,
  longitude: 7.9604,
  postal_code: '4617',
  time_zone: 'Europe/Oslo',
  speed: '836.20 MS'
}
*/

and so on...

After these examples, lets dive into the real library referrence!

Classes

  • ProxySpace

  • ProxySpaceV2 extends ProxySpace

In all cases use ProxySpaceV2class

Class: ProxySpaceV2:

Constructor

accesor: (headers?: {[key: string]: string}, proxy?: ProxyConfig, timeout?: number)

Example

const { ProxySpaceV2 } = require("proxyspace");

var util = new ProxySpaceV2(
  {
    "cache-control": "no-store",
  },
  undefined,
  3000
);

Our module will use the header given at argument position 1, because argument 2 is undefined it won't be using a proxy and the third argument is the global timeout for all requests. Later on after initialization you can anytime change these behaviors by the <class>.proxySpace.defaults.timeout properties etc... Example to add proxy if we didnt add it at initialization time but wanted to add it later on:

const { ProxySpaceV2 } = require("proxyspace");

var util = new ProxySpaceV2(
  {
    "cache-control": "no-store",
  },
  undefined,
  3000
);

util.proxySpace.defaults.proxy = {
  auth: {
    username: "rvugmczm",
    password: "3j296ogi3b86",
  },
  host: "2.56.119.93",
  port: 5074,
  protocol: "http",
};

Methods

GeoLocation(ip?: string): Promise<GEO_API_RESPONSE>

If ip is not defined it will lookup your local IP.

GEO_API_RESPONSE is a JSON object:

{
    asn_number: number;
    asn_organization: string;
    city: string;
    country: string;
    country_code: string;
    ip: string;
    latitude: number;
    longitude: number;
    postal_code: string;
    time_zone: string;
    speed: string;
}

Uptime(): Promise<API_UPTIME>

Gets the ProxySpace API uptime.

API_UPTIME is a JSON object:

{
    days: number;
    hours: number;
    minutes: number;
    seconds: number;
    weeks: number;
    years: number;
    speed: string;
}

IP_Rangify(country: ProxySpace_Countries = ProxySpace_Countries.US): Promise<Subnet>

country is a country code with uppercases. You can do something like this to use our predefined constant enum values:

const { ProxySpaceV2 } = require("proxyspace");
const { ProxySpace_Countries } = require("proxyspace/dist/@types");

(async () => {
  var util = new ProxySpaceV2(
    {
      "cache-control": "no-store",
    },
    undefined,
    2000
  );

  let subnets = await util.IP_Rangify(ProxySpace_Countries.NL);
})();

Subnet is a JSON object:

{
    net: Array<{
        ip: Netmask;
        country: ProxySpace_Countries;
        live: "yes" | "no" | "not-checked";
    }>;
}

Proxify(protocol: ProxyProtocols, output: "array" | "plaintext"): Promise<Buffer | Array<string>>

ProxyProtocols can be one of "http" | "https" | "socks4" | "socks5"

output controls the behave about what kind of object to return from the method. In this case either an array or plaintext.

CheckProxy(proxyList: Array<string>, protocol: "http" | "https" | "socks4" | "socks5", callback: (err: Error | null, res: any) => any): boolean

proxyList has to be an array of Proxies in <ip>:<port> format. You can use Proxify method to get proxylists from our API.

protocol has to be one of: "http" | "https" | "socks4" | "socks5"

callback this is the function to execute to provide back the working proxies. So the res argument (2th arg) will contain the working proxy.

callback needs to be a function with err: Error | null, res: any

Because proxy checking uses a in-memory worker enqueue pool to check within rapid speed. Each working proxy will call the callback again! So res does not contain all working proxies at once, it calls once upon a proxy.

Example

const { ProxySpaceV2 } = require("proxyspace");

var util = new ProxySpaceV2();
util.proxySpace.defaults.timeout = 10000;

util.Proxify("http", "array").then((proxyList) => {
  util.CheckProxy(proxyList, "http", (err, res) => {
    process.stdout.write(res);
  });
});

Credits

  • ProxySpace

  • Z3NTL3 - lead maintainer of the module