1

in ruby we can do it like this

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."

it will like this

enter image description here

but how to do it in nodejs?

Tiankui
  • 322
  • 4
  • 8

1 Answers1

10

Taken from the node.js documentation of 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();
});
TheHippo
  • 61,720
  • 15
  • 75
  • 100