L
L
LemanRass092017-01-07 18:03:20
Node.js
LemanRass09, 2017-01-07 18:03:20

Is there a proxy server service for node.js?

Hello. I have a couple of questions about working with proxy servers in node.js.
Below I will write a couple of my assumptions, please correct me if I'm wrong.
1. I understand that for node.js any proxy server found on the Internet will not work. I suspect that it must be specially prepared to work with node.js sources.
2. Apparently, I will need to raise my own proxy server, which will have to accept responses from other proxy servers to which I send the request.
3. The scheme of working with proxy servers on node.js should look something like this: I create a server to receive responses from proxy servers and listen on a specific port. I send a request to the proxy server indicating the ip and port of the proxy server that I currently want to use, the ip and port of my server to receive a response and somehow place my own request that should be executed on the proxy server and the result of which should be returned proxy server to my own.
4. Could you show an example of how you can make a proxy server let me return the html of a specific page?
5. Could you advise me a package from the npm repository for node.js, taking into account my needs described in these arguments?
6. Could you advise me a site where I can get free access or even buy access to a certain number of proxy servers that are suitable for working through node.js? Interested in a decent number of servers, for example 50.
Thanks in advance for your answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton L, 2017-01-07
@LemanRass09

The first three points by, because. there are no special proxies for a node. Prosky is independent of the platform you are developing on.
4. https://github.com/request/request/blob/master/REA...
5. https://github.com/chill117/proxy-lists
6. Don't buy anything, look at point 5.

//Для начала установите модуль request
//npm i request --save
/**
 * make get request through proxy
 * @param {string} url -   uri of resource
 * @param {object[]} proxyList - array of proxies
 * @param {string} proxyType='http' - type of proxy
 * @param {function} cb - callback
 */
const testProxy = (url, proxyList, proxyType, cb) => {
    if(!(proxyList instanceof Array) && !(cb instanceof Function) && !url){
        throw new Error('testProxy() arguments not set');
    }
    proxyType = proxyType || 'http';

    const proxyIndex = parseInt(Math.random() * (proxyList.length - 1));
    const proxy = proxyList[proxyIndex];
    const proxyUrl = `${proxyType}://${proxy.ipAddress}:${proxy.port}`;
    
    const anyParam = {method : 'GET', proxy : proxyUrl, strictSSL: false};
    
    request(url, anyParam, (error, response, body) => {
        if(error){
            cb(error);
        } else {
            cb(null, response, body);
        }
    });
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question