Readline

readline.createInterface()

Creates a line-oriented input interface. It starts consuming its input immediately, so register handlers before unrelated asynchronous work. Close it in cleanup. Tested on Node.js 22.16.0. Example output (one line per entry): ["one|two"].

Formal Syntax & Structure

nodejs syntaxnodejs
readline.createInterface(options)

Parameters & Attributes

NameTypeDescription
optionsobjectInput stream and optional output configuration.

Return Value

Interface

Line interface.

Working Example

Example Snippetnodejs
import { createInterface } from 'node:readline';import { Readable } from 'node:stream';const rl = createInterface({ input: Readable.from(['one\ntwo\n']), crlfDelay: Infinity });try {    const lines = [];    for await (const line of rl)        lines.push(line);    console.log(lines.join('|'));}finally {    rl.close();}
Node.js Reference