Node-Stream Utilities

1.7.0 · abandoned · verified Sun Apr 19

Node-Stream is a utility library designed to simplify working with Node.js stream APIs by exposing a collection of array-like methods for consuming, creating, and manipulating streams. Originally aiming to resolve common misunderstandings and misuse of Node's core stream interface, it provides methods like `where`, `sort`, `take`, `stringify`, and `intersperse` that return Streams3 instances. The library was built to work with Node.js versions 0.12 and newer, supporting the Streams3 implementation. However, the package, currently at version 1.7.0, was last published approximately 9 years ago (as of April 2026), indicating it is no longer actively maintained and has been effectively abandoned. While it aimed to offer a more accessible API for Node.js streams, its age means it does not support modern Node.js stream features like `stream.promises` or async iterators, nor does it provide ESM compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates piping a mock readable stream through several `node-stream` utility functions to filter, sort, limit, and format data, finally writing it to standard output. It simulates fetching the 5 most recent posts by a specific author.

const nodeStream = require('node-stream');
const { Readable } = require('stream');

// Mock a database read stream for demonstration purposes
const mockData = [
  { id: 1, type: 'post', author: 'stezu', content: 'First post' },
  { id: 2, type: 'comment', author: 'guest', content: 'Nice one!' },
  { id: 3, type: 'post', author: 'stezu', content: 'Second post' },
  { id: 4, type: 'post', author: 'other', content: 'Another post' },
  { id: 5, type: 'post', author: 'stezu', content: 'Third post' },
  { id: 6, type: 'post', author: 'stezu', content: 'Fourth post' },
  { id: 7, type: 'post', author: 'stezu', content: 'Fifth post' }
];

const db = {
  createReadStream: () => {
    let index = 0;
    return new Readable({
      objectMode: true,
      read() {
        if (index < mockData.length) {
          this.push(mockData[index++]);
        } else {
          this.push(null);
        }
      }
    });
  }
};

// Get the 5 most recent posts by stezu
db.createReadStream()
  .pipe(nodeStream.where({ type: 'post', author: 'stezu' }))
  .pipe(nodeStream.sort((a, b) => a.id < b.id ? 1 : -1)) // Sort descending by ID for 'most recent'
  .pipe(nodeStream.take(5))
  .pipe(nodeStream.stringify()) // Convert objects to JSON strings
  .pipe(nodeStream.intersperse('\n')) // Add newlines between items
  .pipe(process.stdout);

view raw JSON →