A
A
alexdora2016-06-13 14:13:42
Node.js
alexdora, 2016-06-13 14:13:42

How to run a Node.js WebSockets script under different proxies?

I understand how to fully configure the entire Node.js so that it comes under Proxy. Is it possible somehow to assign a separate Proxy server to each copy of the running script and so that it goes through it?
ADD: There is a js script written in Nodejs + https://github.com/websockets/ws . The task is to run a copy of the script, but so that the connection is through a third-party specified proxy, available technologies on the HTTP/HTTPS/SOCKS4,5 proxy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Puzynya, 2016-06-16
@alexdora

We take out the proxy address into a variable, then, if desired, we calculate this variable depending on the environment or on the parameters passed

var proxyAddress = process.env.PROXY_ADDRESS;

// node app.js --proxy_address='...'
var proxyAddress = process.argv[2].split('=')[1];

Accordingly, we either fork the process with the necessary arguments, or with the necessary environment:
child_process.fork('app.js', '--proxy_address=...');

child_process.fork('app.js', {
    env: {
        PROXY_ADDRESS: '...'
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question