繁体   English   中英

如何使用 NPM 为 node.js 安装/下载提示命令

[英]How do I install/download the prompt command with NPM for node.js

我对 JavaScript 比较陌生,尝试安装提示时我无法让 NPM 工作。 我正在尝试编写一个程序,该程序从控制台获取用户输入并将其转换为其他变量。 它应该做的是询问华氏温度,然后将其转换为摄氏温度和开尔文温度。 有人知道如何获取提示命令吗?

如果您想读取用户输入,可以使用readline节点模块

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();
});

有关更多详细信息,请参阅如何提示用户从命令行脚本输入?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM