createInterface
external fun createInterface(input: ReadableStream, output: WritableStream = definedExternally, completer: Completer = definedExternally, terminal: Boolean = definedExternally): Interface(source)
external fun createInterface(input: ReadableStream, output: WritableStream = definedExternally, completer: AsyncCompleter = definedExternally, terminal: Boolean = definedExternally): Interface(source)
The readlinePromises.createInterface()
method creates a new readlinePromises.Interface
instance.
const readlinePromises = require('node:readline/promises');
const rl = readlinePromises.createInterface({
input: process.stdin,
output: process.stdout,
});
Content copied to clipboard
Once the readlinePromises.Interface
instance is created, the most common case is to listen for the 'line'
event:
rl.on('line', (line) => {
console.log(`Received: ${line}`);
});
Content copied to clipboard
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).
Since
v17.0.0