Dev HelpersOpen library
← Back

Pass stream chunks through a pipeline

Pass stream chunks through a pipeline in JavaScript.

Open this example in the interactive library

Source code

import { Readable, Writable } from "node:stream";
import { pipeline } from "node:stream/promises";
const chunks = [];
await pipeline(
  Readable.from(["a", "b"]),
  new Writable({
    write(chunk, _, done) {
      chunks.push(chunk.toString());
      done();
    },
  }),
);
console.log(chunks);

Sample output

[ 'a', 'b' ]