首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Node 17:支持 Readline Promise API

Node 17:支持 Readline Promise API

作者头像
ConardLi
发布于 2021-11-05 11:30:43
发布于 2021-11-05 11:30:43
1.5K0
举报
文章被收录于专栏:code秘密花园code秘密花园

readline 模块提供了一个接口,用于一次一行地从可读流(例如 process.stdin)中读取数据。

下面简单示例说明了 readline 模块的基本用法:

代码语言:javascript
复制
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();

完

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-10-30,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档