codegurukool.com · Free coding tutorials & online compiler

Home › Node.js Tutorial › Node.js streams

Node.js streams

Process data piece by piece.

A stream handles data in chunks, so big files do not fill memory. Readable.from makes a stream from an array, and the data and end events deliver the pieces.

Example code

const { Readable } = require("stream");
const r = Readable.from(["a", "b", "c"]);
let out = "";
r.on("data", function (c) { out += c; });
r.on("end", function () { console.log(out); });

Run this code in the online editor

← Node.js errorsLive project: Mini task API →