Readline

rl[Symbol.asyncIterator]()

Allows line-by-line asynchronous iteration. This example consumes finite trusted input; application readers need explicit input-size and error policies. Tested on Node.js 22.16.0. Example output (one line per entry): ["5"].

Formal Syntax & Structure

nodejs syntaxnodejs
rl[Symbol.asyncIterator]()

Return Value

AsyncIterator<string>

Iterator over lines.

Working Example

Example Snippetnodejs
import { createInterface } from 'node:readline';import { Readable } from 'node:stream';const rl = createInterface({ input: Readable.from(['2\n3\n']) });try {    let total = 0;    for await (const line of rl)        total += Number(line);    console.log(total);}finally {    rl.close();}
Node.js Reference