NodeJS

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

Friedrich Kräft avatar
Written by Friedrich Kräft
Updated over a week ago

NodeJS Code

In this example, we use the Residential proxy below:

resi.ipv6.plainproxies.com:8080:customer:product--resi6--pass--nicepass

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 = "resi.ipv6.plainproxies.com:8080:customer:product--resi6--pass--nicepass";
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);
});

Did this answer your question?