A simple proxy chooser to choose proxies from a list or test proxies, only supports http/https proxies.
GitHub: https://github.com/DemonMartin/proxychooser/
npm install proxychooser
const ProxyChooser = require("proxychooser");
const proxyList = [
"proxy1:port1",
"name:pw@proxy:port"
];
const proxyChooser = new ProxyChooser(proxyList, {
verbose: true,
maxTimeout: 1000,
forceRetry: false
});
proxyChooser.getProxy().then(proxy => {
console.log(proxy);
});
const singleProxy = new ProxyChooser([], {
verbose: true,
maxTimeout: 1000
});
singleProxy.testProxy(proxyList[0]).then(proxy => {
console.log(proxy);
});
proxyList
(Array): List of proxies to use.options
(Object): Options to use.verbose
(boolean, optional): If true, will log to console. Default: false.verboseIdentifier
(string, optional): Identifier for verbose. Default: "[proxyChooser]".maxTimeout
(number, optional): Max timeout for a request. Default: 1000.pingUrl
(string, optional): URL to use to check proxy. Default: "http://myexternalip.com/raw".forceRetry
(boolean, optional): Whether functiongetProxy
should continue searching even on error. Default: false.
Resets the proxy list.
- Returns: boolean - Whether it failed or not.
Adds proxies to the proxy list.
proxies
(Array): List of proxies to add.- Returns: boolean - Whether it failed or not.
Gets the ping between the client and the pingUrl
.
- Returns: Promise<number> - Ping in ms.
Tests the given proxy for connectivity.
proxy
(string): Proxy to test.- Returns: Promise<boolean> - Whether the proxy is working or not.
Resets the cache of tested proxies.
- Returns: boolean - Whether the cache was reset or not.
Gets the next working proxy from the proxy list.
- Returns: Promise<string|null> - Next working proxy or null if no proxy is available.
MIT License
Demon Martin