http-proxy-agent vs http-proxy-middleware vs http-proxy vs express-http-proxy vs proxy-middleware
Node.js Proxy Middleware Packages Comparison
1 Year
http-proxy-agenthttp-proxy-middlewarehttp-proxyexpress-http-proxyproxy-middleware
What's Node.js Proxy Middleware Packages?

These packages provide various functionalities for creating HTTP proxies in Node.js applications. They help in routing requests to different servers, handling responses, and managing various aspects of HTTP communication. Each package has its own unique features and use cases, making them suitable for different scenarios in web development, such as API gateways, load balancing, and request forwarding.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
http-proxy-agent56,534,03498923.3 kB33a year agoMIT
http-proxy-middleware17,080,69310,87681.4 kB1124 months agoMIT
http-proxy16,573,82414,012-6125 years agoMIT
express-http-proxy588,2921,241137 kB1476 months agoMIT
proxy-middleware510,529144-209 years agoMIT
Feature Comparison: http-proxy-agent vs http-proxy-middleware vs http-proxy vs express-http-proxy vs proxy-middleware

Integration with Express

  • http-proxy-agent:

    This package does not integrate directly with Express and is more of a utility for creating HTTP agents for use with other libraries.

  • http-proxy-middleware:

    This package is built as middleware for Express, making it very easy to set up and use for route-specific proxying.

  • http-proxy:

    While not specifically tied to Express, http-proxy can be used within Express applications, but requires more manual setup compared to express-http-proxy.

  • express-http-proxy:

    This package is designed specifically for use with Express.js, allowing you to seamlessly integrate proxying capabilities into your existing Express middleware stack.

  • proxy-middleware:

    This package can be used in any Node.js application, including Express, but is not specifically tailored for it.

Configuration Options

  • http-proxy-agent:

    Focuses on agent configuration options, allowing you to specify proxy settings and manage connection pooling, but does not handle request/response modification.

  • http-proxy-middleware:

    Includes options for path rewriting, filtering requests, and customizing response handling, making it versatile for middleware use.

  • http-proxy:

    Provides extensive options for customizing the proxy behavior, including handling websockets, modifying requests and responses, and error handling.

  • express-http-proxy:

    Offers a variety of configuration options such as handling timeouts, modifying headers, and logging requests, making it flexible for different use cases.

  • proxy-middleware:

    Offers basic configuration options, but is less feature-rich compared to the other packages.

Use Cases

  • http-proxy-agent:

    Useful for scenarios where you need to route outgoing requests through a proxy server, especially in environments with strict network policies.

  • http-proxy-middleware:

    Perfect for creating a proxy for specific routes in an Express application, such as when you want to forward requests to a microservice architecture.

  • http-proxy:

    Best suited for custom proxy solutions where you need complete control over the request and response lifecycle, such as building a custom load balancer.

  • express-http-proxy:

    Ideal for applications that need to proxy API requests to a backend server while maintaining the Express.js routing and middleware capabilities.

  • proxy-middleware:

    Great for lightweight proxying needs in any Node.js application, especially when you want to keep things simple.

Performance

  • http-proxy-agent:

    Performance depends on the underlying HTTP library, but it is generally efficient for managing outgoing requests through a proxy.

  • http-proxy-middleware:

    Performance is good for typical use cases, but may vary based on the complexity of the middleware logic you implement.

  • http-proxy:

    Highly performant and efficient, designed for low-level control, making it suitable for high-throughput applications.

  • express-http-proxy:

    Performance is generally good, but may introduce some overhead due to the additional middleware layer in Express.

  • proxy-middleware:

    Lightweight and efficient, making it suitable for simple proxying tasks without much overhead.

Community and Support

  • http-proxy-agent:

    Part of the broader HTTP agent ecosystem, with good documentation but less community focus compared to others.

  • http-proxy-middleware:

    Benefits from the popularity of Express, with a supportive community and many examples available.

  • http-proxy:

    Widely used and well-documented, with a large user base providing community support and contributions.

  • express-http-proxy:

    Has a strong community due to its integration with Express, with plenty of resources and examples available.

  • proxy-middleware:

    Smaller community compared to others, but still has adequate documentation and usage examples.

How to Choose: http-proxy-agent vs http-proxy-middleware vs http-proxy vs express-http-proxy vs proxy-middleware
  • http-proxy-agent:

    Opt for http-proxy-agent when you need to create an HTTP agent that can be used with other HTTP libraries, particularly when you want to route requests through a proxy server without modifying the request handling logic.

  • http-proxy-middleware:

    Use http-proxy-middleware if you want a simple middleware solution for Express that allows you to easily create a proxy for specific routes, with built-in support for various options like path rewriting and logging.

  • http-proxy:

    Select http-proxy for a low-level, flexible proxying solution that allows for fine-grained control over the proxying process, suitable for custom implementations where you need to handle requests and responses manually.

  • express-http-proxy:

    Choose express-http-proxy if you are working within an Express.js application and need a straightforward way to proxy requests to another server while maintaining the Express middleware structure.

  • proxy-middleware:

    Choose proxy-middleware for a lightweight solution that can be easily integrated into any Node.js application, especially when you need a simple way to proxy requests without the overhead of a full framework.

README for http-proxy-agent

http-proxy-agent

An HTTP(s) proxy http.Agent implementation for HTTP

This module provides an http.Agent implementation that connects to a specified HTTP or HTTPS proxy server, and can be used with the built-in http module.

Note: For HTTP proxy usage with the https module, check out https-proxy-agent.

Example

import * as http from 'http';
import { HttpProxyAgent } from 'http-proxy-agent';

const agent = new HttpProxyAgent('http://168.63.76.32:3128');

http.get('http://nodejs.org/api/', { agent }, (res) => {
  console.log('"response" event!', res.headers);
  res.pipe(process.stdout);
});

API

new HttpProxyAgent(proxy: string | URL, options?: HttpProxyAgentOptions)

The HttpProxyAgent class implements an http.Agent subclass that connects to the specified "HTTP(s) proxy server" in order to proxy HTTP requests.

The proxy argument is the URL for the proxy server.

The options argument accepts the usual http.Agent constructor options, and some additional properties:

  • headers - Object containing additional headers to send to the proxy server in each request. This may also be a function that returns a headers object.

    NOTE: If your proxy does not strip these headers from the request, they will also be sent to the destination server.