0.1.0 • Published 10 years ago

micron-throttle v0.1.0

Weekly downloads
9
License
-
Repository
github
Last release
10 years ago

Micron-throttle

Token bucket based HTTP request throttle for Node.js

Build Status

Installation

npm install micron-throttle

Basic Use

The throttle module can be used in just about any application that supports the function (req, res, next) middleware convention (such as express, connect, union or restify). For example in restify:

var http        = require('restify'),
    throttle    = require('micron-throttle');

// Create the server and pass-in the throttle middleware
var server      = restify.createServer();
server.use(throttle({
    burst: 100,
    rate: 50,
    ip: true,
    overrides: {
        '192.168.1.1': {
            rate: 0,        // unlimited
            burst: 0
        }
    }
}));

// Define a route
server.get('/hello/:name', function (req, res, next) {
    res.send('hello ' + req.params.name);
});

// Listen
server.listen(3333);

Options

Testing

npm test

Credits

This module is adapted from restify's throttle plug-in – originally developed by Mark Cavage.