//Make sure you have Node and NPM installed
//Run "npm install prompt-sync" in the terminal
const prompt = require('prompt-sync')();
const name = prompt('What is your name?');
console.log(`Hey there ${name}`);
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
readline.question('Who are you?', name => {
console.log(`Hey there ${name}!`);
readline.close();
});
const prompt = require("prompt-sync")();
const input = prompt("What is your name? ");
console.log(`Oh, so your name is ${input}`);
--------------- easiest method I found---------------------------
Run npm install prompt-sync in the terminal
const prompt = require('prompt-sync')();
var name = prompt('what is your name?');
console.log(name);
--------------------------------------------------------------
process.stdin.on('data', (data) => {
console.log(`You typed ${data}`);
})
// first install prompt-sync:
// npm install prompt-sync
const prompt = require("prompt-sync")({ sigint: true });
const age = prompt("How old are you? ");
console.log(`You are ${age} years old.`);
// npm i readline-sync
import readlineSync from 'readline-sync';
const text = readlineSync.question('enter text:');
const password = readlineSync.question('password:', {
hideEchoBack: true // The typed text on screen is hidden by `*` (default).
});