如何要求在命令行中问题的NodeJS

这个问题已经在这里有一个答案:

  • 从控制台读取值,交互3回答

在Ruby中,我们可以像下面这样做

print "How old are you? " age = gets.chomp() print "How tall are you? " height = gets.chomp() print "How much do you weigh? " weight = gets.chomp() puts "So, you're #{age} years old, #{height} tall and #{weight} heavy."

它会喜欢这个

如何要求在命令行中问题的NodeJS


但如何做到这一点的NodeJS中?

--------------解决方案-------------

从Node.js的文件采取readline

var readline = require('readline');

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question("What do you think of node.js? ", function(answer) {
console.log("Thank you for your valuable feedback:", answer);

rl.close();
});

分类:JavaScript的 时间:2015-03-15 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 1.645 (s). 10 q(s)