proxies-pool
Version:
HTTP/HTTPS tunnel proxy for luminati.io using round robin strategy.
103 lines (64 loc) • 3.25 kB
Markdown
# proxies-pool

[](https://travis-ci.org/Kikobeats/proxies-pool)
[](https://coveralls.io/github/Kikobeats/proxies-pool)
[](https://david-dm.org/Kikobeats/proxies-pool)
[](https://david-dm.org/Kikobeats/proxies-pool#info=devDependencies)
[](https://www.npmjs.org/package/proxies-pool)
> Simple way to handle a pool of proxies using round robin strategy.
## Install
```bash
$ npm install proxies-pool --save
```
## Usage
The instance is a function that returns a different proxy every time you call it, using [round robin](https://en.wikipedia.org/wiki/Round-robin_DNS) algorithm.
```js
const proxiesPool = require('proxies-pool')
const proxies = ['proxy1', 'proxy2', 'proxy3']
const proxyPool = proxiesPool(proxies)
const url = 'http://lumtest.com/echo.json'
const createAgent = proxy => ({
agent: {
http: tunnel.httpOverHttp({ proxy })
}
})
;(async () => {
// => it uses 'proxy1'
await got(url, { agent: createAgent(proxyPool()) })
// => it uses 'proxy2'
await got(url, { agent: createAgent(proxyPool()) })
// => it uses 'proxy3'
await got(url, { agent: createAgent(proxyPool()) })
// => it uses 'proxy1'
await got(url, { agent: createAgent(proxyPool()) })
})()
```
## API
### `proxyPool = proxiesPool(proxies, [fromIndex])`
#### proxies
*Required*<br>
Type: `array`
A collection of proxies to use.
You can get it from your [luminati.io](https://luminati.io) control panel or any compatible provider.

Read more at [documentation](https://luminati.io/faq#download-ips).
#### fromIndex
Type: `number`<br>
Default: `0`
It specifies the position of the `proxies` collection to start.
### `proxyPool`
The instance is a function that returns a different proxy every time you call it, using [round robin](https://en.wikipedia.org/wiki/Round-robin_DNS) algorithm.
#### .current()
Returns the current proxy tunnel credential.
#### .index()
Returns the current proxy tunnel index from the `proxies` provided.
#### .next()
Returns the next proxy tunnel credential.
#### .previous()
Returns the previous proxy tunnel credential.
#### .size()
Returns the number of proxies in the pool.
## License
**proxies-pool** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/proxies-pool/blob/master/LICENSE.md) License.<br>
Authored and maintained by Kiko Beats with help from [contributors](https://github.com/Kikobeats/proxies-pool/contributors).
> [kikobeats.com](https://kikobeats.com) · GitHub [Kiko Beats](https://github.com/Kikobeats) · Twitter [@Kikobeats](https://twitter.com/Kikobeats)