node terminal readline console 1

node terminal readline console

before executing the command node in terminal you have to install
  :~$ npm install prompt-sync
if you havent already.
then inside node
  >const prompt = require('prompt-sync')();
  >name = prompt('What is your name? '); michael
  >console.log(`Hey there ${name}`);
Hey there michael

Here is what the above code is Doing:
1. We’re requiring the prompt-sync module and assigning it to a variable called prompt.
2. We’re using the prompt function to ask the user for their name.
3. We’re using the console.log function to print out a greeting to the user.

Similar Posts