http-proxy-middleware
http-proxy-middleware is a one-liner Node.js proxy middleware for Express, Connect, and browser-sync, powered by the http-proxy library. It provides a simple wa…
Installation
npm install http-proxy-middleware
yarn add http-proxy-middleware
pnpm add http-proxy-middleware
Import
import { createProxyMiddleware } from 'http-proxy-middleware';Quick Example
import express from 'express';
import { createProxyMiddleware } from 'http-proxy-middleware';
const app = express();
app.use('/api', createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
}));About http-proxy-middleware
http-proxy-middleware is a one-liner Node.js proxy middleware for Express, Connect, and browser-sync, powered by the http-proxy library. It provides a simple way to proxy HTTP requests from your Node.js server to another server, commonly used during development to proxy API calls to a backend server to avoid CORS issues, and in production for microservice routing, load balancing, and API gateway patterns. The middleware supports URL rewriting with pathRewrite rules, WebSocket proxying, custom request and response interceptors, header modification, target selection based on request properties, and SSL/TLS configuration for proxying to HTTPS targets. Common use cases include proxying /api requests from a React or Vue development server to a backend API, routing microservice requests based on URL prefixes, and implementing a simple API gateway that distributes requests to different backend services. The middleware handles connection pooling, error recovery, and timeout configuration for reliable proxy operation. It integrates directly with webpack-dev-server and Vite's proxy configuration, making it a foundational tool in modern frontend development workflows.
Quick Facts
| Package | http-proxy-middleware |
| Category | HTTP |
| Weekly Downloads | 8M+ |
| License | MIT |
| Install | npm install http-proxy-middleware |
Related Packages
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
CORS (Cross-Origin Resource Sharing) is an Express/Connect middleware that enables cross-origin requ…
Compression is a Node.js middleware that compresses HTTP response bodies using gzip, deflate, or Bro…
Vite is a next-generation frontend build tool created by Evan You (creator of Vue.js) that provides …
Webpack is a powerful and highly configurable static module bundler for modern JavaScript applicatio…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.