readline 模块提供了一个接口,用于一次一行地从可读流(例如 process.stdin)中读取数据。
下面简单示例说明了 readline 模块的基本用法:
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from '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();
完