Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function createInterface
Re-export
import { createInterface } from "https://deno.land/std@0.145.0/node/readline.ts";

The readline.createInterface() method creates a new readline.Interfaceinstance.

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

Once the readline.Interface instance is created, the most common case is to listen for the 'line' event:

rl.on('line', (line) => {
  console.log(`Received: ${line}`);
});

If terminal is true for this instance then the output stream will get the best compatibility if it defines an output.columns property and emits a 'resize' event on the output if or when the columns ever change (process.stdout does this automatically when it is a TTY).

When creating a readline.Interface using stdin as input, the program will not terminate until it receives EOF (Ctrl+D on Linux/macOS, Ctrl+Z followed by Return on Windows). If you want your application to exit without waiting for user input, you can unref() the standard input stream:

process.stdin.unref();

Parameters

optional
output: WritableStream
optional
completer: Completer | AsyncCompleter
optional
terminal: boolean

Parameters

options: ReadLineOptions