How to take in text input from a keyboard and store it into a variable?

Zemprof picture Zemprof · Nov 1, 2013 · Viewed 24k times · Source

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!

Answer

Harlin picture Harlin · May 27, 2016

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