Node.js Transform stream that passes data through at `n` bytes per second
Latest commit f3a9e41 Mar 7, 2013 @TooTallNate v1.0.3
Failed to load latest commit information.
example example: add quick stdio example Feb 9, 2013
test test: update test Readable stream classes for node v0.9.11 API changes Mar 7, 2013
.gitignore ignore root level ?.js files Feb 9, 2013
.travis.yml travis: don't test node v0.7.x Feb 16, 2013
LICENSE update license Feb 9, 2013 add API section to README Feb 10, 2013
package.json v1.0.3 Mar 7, 2013
throttle.js add API section to README Feb 10, 2013


Node.js Transform stream that passes data through at n bytes per second

Build Status

This module offers a Throttle passthrough stream class, which allows you to write data to it and it will be passed through in n bytes per second. It can be useful for throttling HTTP uploads or to simulate reading from a file in real-time, etc.


$ npm install throttle


Here's an example of throttling stdin at 1 byte per second and outputting the data to stdout:

var Throttle = require('throttle');

// create a "Throttle" instance that reads at 1 bps
var throttle = new Throttle(1);


We can see it in action with the echo command:



The Throttle passthrough stream class is very similar to the node core stream.Passthrough stream, except that you specify a bps "bytes per second" option and data will not be passed through faster than the byte value you specify.

You can invoke with just a bps Number and get the rest of the default options. This should be more common:

process.stdin.pipe(new Throttle(100 * 1024)).pipe(process.stdout);

Or you can pass an options Object in, with a bps value specified along with other options:

var t = new Throttle({ bps: 100 * 1024, chunkSize: 100, highWaterMark: 500 });