简体   繁体   English

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

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

I am relatively new to JavaScript and I can't get NPM to work when trying to install prompt.我对 JavaScript 比较陌生,尝试安装提示时我无法让 NPM 工作。 I am trying to code a program that takes user input from the console and convert it into other variables.我正在尝试编写一个程序,该程序从控制台获取用户输入并将其转换为其他变量。 What it is supposed to do is ask for the temperature in Fahrenheit take your input and then convert it into Celsius and Kelvin.它应该做的是询问华氏温度,然后将其转换为摄氏温度和开尔文温度。 Does anybody know how to get the prompt command?有人知道如何获取提示命令吗?

if you would like to read a user input, you can use readline node modules如果您想读取用户输入,可以使用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();
});

for more details, see How do I prompt users for input from a command-line script?有关更多详细信息,请参阅如何提示用户从命令行脚本输入?

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

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