Node.js Readline
readline can turn a stream into lines for a terminal or text-processing workflow. Give it a clear input source and close its interface when the owner finishes.
How it works
An interactive prompt and a batch file have different completion expectations. This fixture uses a fixed readable stream, so it has no dependency on a reviewer typing into a terminal. crlfDelay handles the supplied line endings deliberately. Trimming a line is appropriate for these controlled kit codes, but may be wrong for a field where surrounding spaces carry meaning. Large lines still need a separate bound before unrestricted processing.
Run the code
Run this example locally with Node.js. The exact sources are reviewed on Node 22.15.1 and Node 24.22.1 unless a specialised lab states otherwise. Save the complete source as line-input.mjs in a separate empty exercises folder and run node line-input.mjs. There is no Node.js browser runner on Bhylu; the plain JavaScript playground does not provide these filesystem, server or process APIs.
Download the complete source. Ordinary Node scripts need no Apache, PHP or MySQL service. File examples own their temporary folders; network fixtures use loopback and available temporary ports.
Example
import { Readable } from 'node:stream';
import { createInterface } from 'node:readline';
const lines = createInterface({
input: Readable.from(['tripod\r\nbinoculars\r\n']),
crlfDelay: Infinity,
});
const codes = [];
try {
for await (const line of lines) codes.push(line.trim());
} finally {
lines.close();
}
console.log(codes.join(','));
Expected result
tripod,binoculars
The two controlled lines become two codes and the input ends naturally. A command-line application using process.stdin should explain what EOF means on its platform and how a cancelled prompt affects the program’s exit status.
Use the Node.js API reference for the precise version contract.