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.
class promises.Interface
extends _Interface
import { promises } from "https://deno.land/std@0.164.0/node/readline.ts";
const { Interface } = promises;

Constructors

new
Interface(
input: ReadableStream | ReadLineOptions,
output?: WritableStream,
completer?: Completer | AsyncCompleter,
terminal?: boolean,
)

Methods

question(query: string, options?: Abortable): Promise<string>
interface promises.Interface
implements _Interface
import { type promises } from "https://deno.land/std@0.164.0/node/readline.ts";
const { Interface } = promises;

The readline/promise module provides an API for reading lines of input from a Readable stream one line at a time.

Methods

question(query: string, options?: Abortable): Promise<string>

The rl.question() method displays the query by writing it to the output, waits for user input to be provided on input, then invokes the callback function passing the provided input as the first argument.

When called, rl.question() will resume the input stream if it has been paused.

If the readlinePromises.Interface was created with output set to null or undefined the query is not written.

If the question is called after rl.close(), it returns a rejected promise.

Example usage:

const answer = await rl.question('What is your favorite food? ');
console.log(`Oh, so your favorite food is ${answer}`);

Using an AbortSignal to cancel a question.

const signal = AbortSignal.timeout(10_000);

signal.addEventListener('abort', () => {
  console.log('The food question timed out');
}, { once: true });

const answer = await rl.question('What is your favorite food? ', { signal });
console.log(`Oh, so your favorite food is ${answer}`);