推荐inquirer.js库,等待接收input输入后,在统一操作!
import inquirer from "inquirer";
(async ()=>{
let password = await inquirer.prompt([
{
type: "password",
name: "name",
message: "输入密码",
},
])
console.log(password)
let content = await inquirer.prompt([
{
type: "input",
name: "name",
message: "输入内容",
},
])
console.log(content)
})()
/**
* ? 输入密码 [hidden]
{ name: '111' }
? 输入内容 222
{ name: '222' }
*/
inquirer.js —— 一个用户与命令行交互的工具_xhsdnn的博客-CSDN博客_inquirer
readline 逐行读取 | Node.js API 文档 【需V18以上版本才支持异步】