Dev Helpers
← Back

Pipe text through a transform

Pipe text through a transform using Node.js.

Open this example in the interactive library

Source code

import {
  Readable,
  Writable,
  Transform,
  PassThrough,
  isReadable,
  isWritable,
} from "node:stream";
import { text, json, arrayBuffer } from "node:stream/consumers";
import { pipeline, finished } from "node:stream/promises";
console.log(
  await text(
    Readable.from(["ab"]).pipe(
      new Transform({
        transform(chunk, enc, done) {
          done(null, chunk.toString().toUpperCase());
        },
      }),
    ),
  ),
);

Sample output

AB