Using Your FoxyProxy Account with Node.js

  1. Home
  2. Programmatically accessing your Proxy
  3. Using Your FoxyProxy Account with Node.js

Here’s a code snippet that uses your FoxyProxy account with Node.js.

This example connects to https://icanhazip.com through a proxy server with your proxy username and password. Be sure to replace username, password, hostname.getfoxyproxy.org and port (typically 3128 or 13129) in this example with your account information.

The Node.js client connects to the proxy server using HTTP and instructs the proxy server to connect to the final destination (icanhazip.com) using HTTPS.

Although this example uses the HTTP proxy server on port 3128, other ports are available (usually 13129) with your account. HTTPS proxy server access is also available on the same ports, which encrypts traffic between your client and FoxyProxy proxy servers. Your account also comes with SOCKS5 proxy server access, typically on port 21. You can find this information by logging into your account at the Control Panel.

var request = require('request');
request({'url': 'https://icanhazip.com',

// Accept self-signed certificates. Remove for production.
strictSSL: false,

// Accept self-signed certificates. Remove for production.
rejectUnauthorized: false,

'proxy': 'http://username:password@hostname.getfoxyproxy.org:3128'},
function (error, response, body) {
if (!error && response.statusCode == 200) console.log(body);
else console.log(error);
});

If successful, the output is the body of https://icanhazip.com. If not successful, the error message is displayed. More info about the request module in Node.js, including how to install it, is here.

Related Articles