W
W
wmw852015-09-14 08:07:21
Node.js
wmw85, 2015-09-14 08:07:21

How to set proxy for all requests coming from node.js script?

I run the sample.js script from the console. It has 3 libs that make requests for http and tcp. The use of proxy in these libs is not provided. It is possible to rewrite them. But I would like to find a better solution. To be more precise - globally prescribe the use of a proxy in the script. Is there such a possibility, please tell me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pomeo, 2015-09-14
@pomeo

This is not a nodejs level, it's easier to do it at the linux level

N
NO_GLITCH, 2015-09-16
@NO_GLITCH

There was a similar question on stackoverflow.com
http proxy is set like this:

var http = require("http");

var options = {
  host: "proxy",
  port: 8080,
  path: "http://www.google.com",
  headers: {
    Host: "www.google.com"
  }
};
http.get(options, function(res) {
  console.log(res);
  res.pipe(process.stdout);
});

TCP requests will already have to be made, as Sergey Ovechkin said , at the system level, for example, you can use the proxychains utility

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question