Skip to content
Justice Tech School

readline

readline reads input line by line. Here a stream stands in for the keyboard.

Example
const readline = require("readline");
const { Readable } = require("stream");
const rl = readline.createInterface({ input: Readable.from(["one\ntwo\nthree\n"]) });
let n = 0;
rl.on("line", (l) => console.log(++n, l));

Result

1 one
2 two
3 three

Exercise

Line event.

rl.on("", fn)

Quiz Test

What does readline emit per line?

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