Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
connect middleware for throttling requests
JavaScript
branch: master
Failed to load latest commit information.
examples init
test vows
.gitignore init
.travis.yml Update master
README.md Update master
index.js init
package.json npm test

README.md

Build Status

Connect Throttle

Installation

npm install connect-throttle

Use it like any other connect middleware.

HowTo throttle your requests

Example 1: Set a fixed one second delay:

var connect = require('connect');
var throttle = require('connect-throttle');
connect()
  .use(throttle.sleep(1000))
  .use(function(req, res) {
    console.log('1 req/s');
    res.end('');
  }).listen(3000);

You can test using apache's ab:

ab localhost:3000/

Example 2: Random delay using a function instead of a fixed value:

var connect = require('connect');
var throttle = require('connect-throttle');
connect()
  .use(connect.responseTime())
  .use(throttle.sleep(function() { return Math.floor(Math.random() * 500); }))
  .use(function(req, res) {
    res.end('');
  }).listen(3000);
Something went wrong with that request. Please try again.