How to simulate slow connection (developer proxy in Node.js)

Update: If you use Chrome then you can use "Throttling" so simulate slow network for all your assets. This should be easier than proxy.

  1. Toggle device mode!
  2. Choose Network type.
  3. Refresh the page

Simulate mobile devices with Device Mode

Proxy:

For some time I wanted to use some proxy for development and testing of eg. slow internet connection, but it was hard to find something useful and free. I know there is Charles but buy it to use it at most one in a month is not for me.

I started thinking about Node.js, maybe I can write proxy for me? But fortunately I found one.

https://github.com/nodejitsu/node-http-proxy

With this module I can write really short code to create slow server:

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

httpProxy.createServer(function (req, res, proxy) {

var buffer = httpProxy.buffer(req);
setTimeout(function () {  
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 8080,
buffer: buffer
});
}, 2000);
}).listen(8000);

Result is proxy server running on port 8000 and returning all content from port 8080 after 2 seconds delay :)



Share on Hacker News
Share on LinkedIn


← Home


Want to learn more?

Sign up to get a digest of my articles and interesting links via email every month.

* indicates required

Please select all the ways you would like to hear from Krzysztof Kula:

You can unsubscribe at any time by clicking the link in the footer of my emails.

I use Mailchimp as a marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.