Using your Proxy Account with Node.js

From FoxyProxy Documentation
Revision as of 03:56, 2 December 2015 by Ejung (Talk | contribs)

Jump to: navigation, search

This Node.js 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 (3128) in this example with your account information. In this example, 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.


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

More info about the request module in Node.js, including how to install it.

If successful, the output is the body of http://icanhazip.com (the IP address of the proxy server). If not successful, the error message is displayed.