The Changelog

Open Source moves fast. Keep up.

node-http-proxy: Reverse proxy for Node.js

Reverse proxies are a pretty standard part of any modern web stack. If you’re dabbling in Node.js and need one to provide caching, added security, or load balancing, you should checkout node-http-proxy from Marak and Charlie at nodejitsu.

To install via npm

npm install http-proxy

A quick example:

var sys = require('sys'),
    http = require('http'),
    httpProxy = require('http-proxy').httpProxy;

http.createServer(function (req, res){
 var proxy = new httpProxy;
 proxy.init(req, res);
 proxy.proxyRequest('localhost', '9000', req, res);

http.createServer(function (req, res){
 res.writeHead(200, {'Content-Type': 'text/plain'});
 res.write('request successfully proxied!' + 'n' + JSON.stringify(req.headers, true, 2));

[Source on GitHub]

Have comments? Send a tweet to @TheChangelog on Twitter.

Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.