Index - 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:readlinemodule.

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 thereadline.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 thereadline.createInterface() method. Every instance is associated with a single 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 thereadlinePromises.createInterface() method. Every instance is associated with a single 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.Readline
No documentation available

Functions

f
clearLine

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

f
clearScreenDown

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

f
createInterface

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

f
cursorTo

The readline.cursorTo() method moves cursor to the specified position in a given 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 current position in a given TTY stream.

f
promises.createInterface

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

Interfaces

I
CursorPos
No documentation available
I
Key
No documentation available
I
ReadLineOptions
No documentation available

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