http-proxy
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
eventemitter3 | 4.0.7 | 9.43 kB | MIT | prod | |
follow-redirects | 1.15.6 | 28.68 kB | MIT | prod | |
requires-port | 1.0.0 | 2.99 kB | MIT | prod |
The "http-proxy" npm package by HTTP Party, is an HTTP programmable proxying library designed to handle HTTP and WebSockets requests. Being suitable for implementing components such as reverse proxies and load balancers, it can be used effectively for HTTP proxying needs.
Here's a basic example of how to use the "http-proxy" package:
var http = require('http');
var httpProxy = require('http-proxy');
// Create a proxy server with a specified target.
var proxy = httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
// Create a targets server which will receive the proxied requests.
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('Request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
In this example, we first import the http
and http-proxy
modules. We then create a proxy server with a specified target URL. Any requests made to this proxy server will be forwarded to the target server located at http://localhost:9000
. This server will respond with a simple message.
The documentation for the "http-proxy" npm package, along with additional use-cases, options, and in-depth explanations of its features, can be found directly on its GitHub repository.