Peek into a fixed-size window on your streams, useful for logging and debugging.


PEEKSTREAM is a simple filtering stream that collects and buffers data inside a configured window as they're being streamed.

Useful for taking a peek at streaming logs or sampling data at intervals.

Also very useful for testing complex stream interactions.

npm install --save peekstream
var peek = require('peekstream').peek;


With your code like this:


You can peek into the stream by changing it to look like this (with child process piping sample):

var ps = peek(child.stdout, process.stdout);
setInterval(function monitorStreamContent() {
  console.log("PIPE: " + ps.window.toString());
}, 1000);


PeekStream inherits from Stream and supports basic read and write operation.

In addition, PeekStream exports a window property that is a Buffer of the data that has been filtered. When source stream emits data the data is appended to the end of the window and any excess from the configured size is trimmed from the beginning of the buffer.

Creates and return a new PeekStream class instance with SRC stream piped through it.

Additionallty, if DEST stream is specified, the returned PeekStream will be piped through the destination stream automatically as well.

SRC and DEST is also accessible from the resulting stream via the source and destination property respectively.

Creates a PeekStream with specified windowing size (defaults to 1 kiB)




Test with

make test
make tdd      # spins a loop 

Compiles to JS with

make all

Something to do:

  • Make PeekStream a two-way stream supporting cases where user wants to pipes the destination stream back into the source stream as well.
  • Returns the destination stream so it is more compatible with how pipe() works (but then how do we returned the PeekStream instance?)
  • Better handling of back-pressure. (Now just always returns true since we don't buffer in the traditional sense.)