Skip to main content
readline - Node documentation

Usage in Deno

import * as mod from "node:readline";

The node:readline module provides an interface for reading data from a Readable stream (such as process.stdin) one line at a time.

To use the promise-based APIs:

import * as readline from 'node:readline/promises';

To use the callback and sync APIs:

import * as readline from 'node:readline';

The following simple example illustrates the basic use of the node:readline module.

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();

Once this code is invoked, the Node.js application will not terminate until the readline.Interface is closed because the interface waits for data to be received on the input stream.

Classes

c
Interface

Instances of the readline.Interface class are constructed using the readline.createInterface() method. Every instance is associated with asingle input Readable stream and a single output Writable stream.The output stream is used to print prompts for user input that arrives on,and is read from, the input stream.

c
promises.Interface

Instances of the readlinePromises.Interface class are constructed using the readlinePromises.createInterface() method. Every instance is associated with asingle input Readable stream and a single output Writable stream.The output stream is used to print prompts for user input that arrives on,and is read from, the input stream.

Functions

f
clearLine

The readline.clearLine() method clears current line of given TTY streamin a specified direction identified by dir.

f
clearScreenDown

The readline.clearScreenDown() method clears the given TTY stream fromthe current position of the cursor down.

f
createInterface

The readline.createInterface() method creates a new readline.Interface instance.

f
cursorTo

The readline.cursorTo() method moves cursor to the specified position in agiven TTY stream.

f
emitKeypressEvents

The readline.emitKeypressEvents() method causes the given Readable stream to begin emitting 'keypress' events corresponding to received input.

f
moveCursor

The readline.moveCursor() method moves the cursor relative to its currentposition in a given TTY stream.

f
promises.createInterface

The readlinePromises.createInterface() method creates a new readlinePromises.Interface instance.

Interfaces

Namespaces

N
promises
No documentation available

Type Aliases

T
AsyncCompleter
No documentation available
T
Completer
No documentation available
T
CompleterResult
No documentation available
T
Direction
No documentation available
T
ReadLine
No documentation available