On April 1, 2021, we are moving all of our QuotaGuard Support Documentation to
https://quotaguard.github.io/qg-docs/
Please Update Your Support Bookmarks
Documentation for this article will be maintained at
https://quotaguard.github.io/qg-docs/nodejs-https.html
Please click on the above link to ensure you are reading
the most recent and updated documentation.
We recommend the https-proxy-agent library for carrying out HTTP operations from Node.js with QuotaGuard.
Installation
When you sign up with QuotaGuard, you will be provided with a unique username and password and a connection string that you can use when configuring your proxy service in your application, for example:
http://username:[email protected]:9293
All requests that you make via this proxy will appear to the destination server to originate from one of the two static IPs you will be assigned when you sign up.
We recommend you store the connection string in an environment variable QUOTAGUARD_URL
. If you have signed up via the add-ons platform on Heroku or cloudControl this variable will be automatically set in your production environment.
Integration
QuotaGuard will work with the standard http library, but we recommend using the https-proxy-agent library for ease of use.
var HttpsProxyAgent = require('https-proxy-agent');
var request = require('request');
var proxy = process.env.QUOTAGUARDSTATIC_URL;
var agent = new HttpsProxyAgent(proxy);
request({
uri: "https://example.com/api",
method: "POST",
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
agent: agent,
timeout: 10000,
followRedirect: true,
maxRedirects: 10,
body: "name=john"
}, function(error, response, body) {
console.log("Error" + error);
console.log("Response: " + response);
console.log("Body: " + body);
});
Other Libraries
We have examples for other common libraries as well, but if you can’t find what you are looking for just send us a Support ticket and we’ll get one sent to you.