import { type Key } from "https://deno.land/std@0.137.0/node/_readline.d.ts";
The readline
module provides an interface for reading data from a Readable
stream (such as process.stdin
) one line at a time. It can be accessed
using:
const readline = require('readline');
The following simple example illustrates the basic use of the readline
module.
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What do you think of Node.js? ', (answer) => {
// TODO: Log the answer in a database
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.