Readline is a core module of NodeJS that is available to us without having to install anything other than NodeJS. It can be used ask/read data of a terminal user.

Suppose we are creating an application that would ask questions from a terminal user. It is an interface where we can read and write data that allows us to easily write code that would ask questions to the user and collect their answers.

so let’s take a look at how can we use Readline module. suppose we have a file questions.js

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

r1.question("how r you doing?", (answer) => {
  console.log(`Answer is ${answer}`);
  process.exit();
});


Output:

(Figure 1: question)
(Figure 2: answer)

Tadda 🙂 ! it is done, hope you fine it interesting. if you want to know more about it you have checkout the official document at https://nodejs.org/api/readline.html#readline

Leave a Reply

Your email address will not be published. Required fields are marked *