What is superagent-proxy?
The superagent-proxy npm package is an extension for the SuperAgent HTTP client library that allows you to route HTTP requests through a proxy server. This can be useful for various purposes such as bypassing network restrictions, anonymizing requests, or testing applications in different network environments.
What are superagent-proxy's main functionalities?
HTTP Proxy
This feature allows you to route HTTP requests through an HTTP proxy server. The code sample demonstrates how to make a GET request to 'http://example.com' through an HTTP proxy server running at 'http://proxy-server:8080'.
const superagent = require('superagent');
require('superagent-proxy')(superagent);
superagent
.get('http://example.com')
.proxy('http://proxy-server:8080')
.end((err, res) => {
if (err) {
console.error(err);
} else {
console.log(res.body);
}
});
HTTPS Proxy
This feature allows you to route HTTPS requests through an HTTPS proxy server. The code sample demonstrates how to make a GET request to 'https://example.com' through an HTTPS proxy server running at 'https://proxy-server:8080'.
const superagent = require('superagent');
require('superagent-proxy')(superagent);
superagent
.get('https://example.com')
.proxy('https://proxy-server:8080')
.end((err, res) => {
if (err) {
console.error(err);
} else {
console.log(res.body);
}
});
SOCKS Proxy
This feature allows you to route HTTP requests through a SOCKS proxy server. The code sample demonstrates how to make a GET request to 'http://example.com' through a SOCKS proxy server running at 'socks5://proxy-server:1080'.
const superagent = require('superagent');
require('superagent-proxy')(superagent);
superagent
.get('http://example.com')
.proxy('socks5://proxy-server:1080')
.end((err, res) => {
if (err) {
console.error(err);
} else {
console.log(res.body);
}
});
Other packages similar to superagent-proxy
axios
Axios is a promise-based HTTP client for the browser and Node.js. It supports making requests through a proxy by configuring the proxy settings in the request options. Compared to superagent-proxy, Axios is more widely used and has built-in support for proxies without needing an additional package.
request
Request is a simplified HTTP client for Node.js with support for proxies. It allows you to configure proxy settings directly in the request options. Although the request package is deprecated, it is still widely used and offers similar proxy functionalities as superagent-proxy.
node-fetch
Node-fetch is a lightweight module that brings window.fetch to Node.js. It supports making requests through a proxy by using the 'http-proxy-agent' or 'https-proxy-agent' packages. Compared to superagent-proxy, node-fetch requires additional configuration for proxy support but is a minimalistic and modern alternative.
superagent-proxy
Request#proxy(uri)
superagent extension
This module extends visionmedia/superagent
's Request
class with
a .proxy(uri)
function. This allows you to proxy the HTTP request through a
proxy of some kind.
It is backed by the proxy-agent
module, so see
its README for more details.
Installation
Install with npm
:
$ npm install superagent-proxy
Example
var request = require('superagent');
require('superagent-proxy')(request);
var proxy = process.env.http_proxy || 'http://168.63.43.102:3128';
request
.get(process.argv[2] || 'https://encrypted.google.com/')
.proxy(proxy)
.end(onresponse);
function onresponse (res) {
console.log(res.status, res.headers);
console.log(res.body);
}
License
(The MIT License)
Copyright (c) 2013 Nathan Rajlich <nathan@tootallnate.net>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.