Search…
⌃K

NodeJS

This article provides an example of using a proxy to make an HTTP request with the NodeJS programming language.

NodeJS Code

In this example, we use the Residential proxy below:
residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22
This proxy is split into four parts separated by colons. We first save the proxy as a string variable, then split it into four parts at each colon (:) and then add it, with authentication, to our proxy dictionary.
const request = require('request');
let proxy_string = "residential.pingproxies.com:7777:customer-tt_pp_lz_5051-sessid-Z9tCGVYHu:23n22mk22";
let proxy_parts = proxy_string.split(':');
let ip_address = proxy_parts[0];
let port = proxy_parts[1];
let username = proxy_parts[2];
let password = proxy_parts[3];
var reqOpts = {
url: "http://www.google.com/",
method: "GET",
headers: { "Cache-Control": "no-cache" },
proxy: `http://${username}:${password}@${ip_address}:${port}`
};
request(reqOpts, function (err, response, body) {
console.log(response.statusCode);
});
Last modified 2mo ago