node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »



A transform stream that passes through writes by default, but only buffers up to a certain number of pending writes when backpressure is applied. New writes will push old writes out of the buffer, so no more than N writes can be pending at a time.

This is especially useful for logging or metrics situations, where:

  1. the data generated is of less value than keeping the process healthy,
  2. and it is difficult or meaningless to apply backpressure to the generation of the data.
var discardStream = require('discard-stream')
var myLogs = discardStream({
  maxBacklog: 100,
  objectMode: true
myHighPerformanceWebserver.on('request', function (req, res) {
// or use it as a transform:


discardStream(options) → DiscardStream

Create a discard stream using the provided stream options. An additional options key, maxBacklog, is required. maxBacklog determines the maximum number of written values to be retained during backpressure — any writes over maxBacklog will result in an old buffered value being discarded.

options.highWaterMark will be ignored — it is always set to 0.

DiscardStream's will never apply backpressure upstream. They act as infinite sinks for data.

discardStream(number) → DiscardStream

A shorthand for creating a discard stream with the following options:

  maxBacklog: number,
  highWaterMark: 0,
  objectMode: true


Get the backlog of queued writes as an array.


"discard" (data)

Emitted when an old write is discarded in favor of a more recent write. This is the last chance the user has to do something with data.