Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including stream-meter with all npm packages installed. Try it out:

var streamMeter = require("stream-meter")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

stream-meter v1.0.4

A stream meter that both counts the bytes piped through it, and can optionally abort on a max size. (e.g. limit a http request size)

Stream Meter


david-dm david-dm

Stream Meter is a... uh, meter for streams.

It is a streams2 Transform stream that passes through content, but counts the number of bytes it forwards.

However, give it a size in bytes and it will abort as soon as that threshold is passed. This is useful for capping your hyperquest or http/https clients or servers content size.

npm install stream-meter


var meter = require("stream-meter")

// make an un-capped meter
var m = meter()
setTimeout(function () {
  // Log how much we saw in a couple seconds.
}, 2000)

// this will abort (with an Error) in the frame where 1024 bytes is reached

// create a 1024 byte-capped meter
var m = meter(1024)
m.on("error", function (e) {
  // log the error but don't kill the process

var hyperquest = require("hyperquest")

var req = hyperquest("")

var meter = require("stream-meter")(1024)
meter.on("error", function (e) {
  console.log("Read %s bytes", meter.bytes)

$ node hypermeter.js 2> /dev/null
Stream exceeded specified max of 1024 bytes.
Read 7377 bytes


var meter = require("stream-meter")

var stream = meter(size)
stream.on("error", function (e) {
  // handle the meter aborting the stream

// read the bytes processed by the meter and passed through to any subsequent streams.
var size = stream.bytes

See test/index.js for additional examples.



Size (in bytes) to trigger the stream to abort. It will complete whatever frame it aborted in, so the size streamed will still be >= size but no more than size + highWaterMark



Number of bytes handled and passed through the meter.




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free