connect-throttle

Connect throttling middleware

npm install connect-throttle
2 downloads in the last month

Connect Throttle

Request throttling using sleep

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);

Try:

ab localhost:3000/

Pass 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);
npm loves you