Skip to content
Justice Tech School

pipeline and Transform

stream.pipeline connects streams and handles errors and cleanup.

Example
const { Readable, Transform, Writable, pipeline } = require("stream");
const up = new Transform({ transform(c, e, cb) { cb(null, c.toString().toUpperCase()); } });
let out = [];
const sink = new Writable({ write(c, e, cb) { out.push(c.toString()); cb(); } });
pipeline(Readable.from(["a", "b"]), up, sink, (err) => console.log(err, out));

Result

undefined [ 'A', 'B' ]

Exercise

Connect streams.

(a, b, cb)

Quiz Test

What does pipeline handle?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.