Nodejs:如何从键盘输入文本输入并将其存储到javascript中的变量中? [英] Nodejs: How to take in text input from a keyboard and store it into a variable in javascript?
本文介绍了Nodejs:如何从键盘输入文本输入并将其存储到javascript中的变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想简单地从键盘上读取文本并将其存储到变量中。因此:
I would just like something simple to read text from a keyboard and store it into a variable. So for:
var color = 'blue'
我希望用户通过键盘提供颜色输入。谢谢!
I would like the user to provide input for the color from the keyboard. Thank you!
推荐答案
如果您不需要异步,我建议使用readline-sync模块。
I would suggest the readline-sync module as well if you don't require something asynchronous.
# npm install readline-sync
const readline = require('readline-sync');
let name = readline.question("What is your name?");
console.log("Hi " + name + ", nice to meet you.");
这篇关于Nodejs:如何从键盘输入文本输入并将其存储到javascript中的变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文