nodejs prompt code example
Example 1: promp node js
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("What is your name ? ", function saveInput(name) {
console.log(`His name is ${name}`);
rl.close();
});
rl.on("close", function saveInput() {
console.log("\nBYE BYE !!!");
process.exit(0);
});
Example 2: js prompt
var answer = prompt('What is your name?','Joe Blogg');
Example 3: javascript prompt
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}