How do I enable http-proxy?

What is node http-proxy?

Http-proxy is a very easy and quick node.js http server proxy. It allows you to expose a web site or an app behind a domain that will forward any traffic to it. It is fast, easy and lightweight.

Using http-proxy means you can get the real benefits of load balancing (if you have more than one web server) by just proxying the request through a single webserver, saving time and money. It is very good for: Storing static files. Creating dynamic caching servers. Serve files for your app. Create load balancing servers that you want to be invisible to the users. Create a proxy server without knowing much about sockets. It is based on a single node.js http server that exposes a local port number.

It is a self-learning proxy server. Let's start with the install: npm install http-proxy. This will make sure the dependencies are installed. Now let's create our proxy server: var http = require('http'); var options = ; http.createServer(options, function (req, res) ).listen(1337);

You can also use this script to run your proxy locally: node http-proxy. If you see an output something like this: This means the server is now running and waiting to get requests from the outside world. Now, if we try to connect to localhost:5000 it won't work. But let's try connecting to our local ip address. We'll find it at

So what we're doing here is redirecting requests to 127.1 port 5000 to 1337 port.

If we try to access to it won't work as we can't do anything over a secure connection. Our proxy needs http-proxy as a dependency and has http module support in it.

How to set http-proxy in node js?

I am using this package http-proxy in my project for setting proxy. But I don't know how to set the proxy server in it. I tried like this: var proxy = new HttpProxy(. });. Now How should I do? Thanks. You can use like this : var http = require('http');. Var url = require('url');. Var proxy = new HttpProxy();. Var urlObject = url.parse(url.format('));
Proxy.proxyhost = urlObject.hostname;
Proxy.proxyport = urlObject.port;
Proxy.target = urlObject.headers = ;

Http.request(proxy).end(function(res));

If you want to proxy from localhost you just have to change localhost by your domain name.

Related Answers

Can you run Nodejs on Windows?

As I'm using apache to serve pages, I'm wondering if node js really requir...

How do I access Tor on Android?

I just read a review of DeepDotWeb, a Tor app for iOS and Mac. The au...

What is a node unblocker?

My friend was given permission to play the game "blockio" at his cl...