node terminal readline console

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('What is your name? ', (name) => {
  console.log(`Hello, ${name}!`);
  rl.close();
});
  1. Import the readline module from the Node.js standard library.
  2. Create a Readline interface using readline.createInterface with process.stdin as the input stream and process.stdout as the output stream.
  3. Prompt the user with the question 'What is your name? ' using rl.question.
  4. Handle the user's input in the callback function, where the provided name is printed to the console along with a greeting.
  5. Close the Readline interface using rl.close() to free up resources and end the program.