how to take in user input from node console code example
Example 1: node js ask for user input
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("What is your name ? ", function(name) {
rl.question("Where do you live ? ", function(country) {
console.log(`${name}, is a citizen of ${country}`);
rl.close();
});
});
rl.on("close", function() {
console.log("\nBYE BYE !!!");
process.exit(0);
});
Example 2: get input from user in nodejs
const prompt = require('prompt-sync')(); const name = prompt('What is your name?');console.log(`Hey there ${name}`);