관리 메뉴

Silver Library (Archived)

[Node.js] - what is readline() modul? 본문

F2. Problem & Solving/Solving

[Node.js] - what is readline() modul?

Chesed Kim 2021. 7. 6. 13:27
반응형

My initial sight:

Looks like readline() is called module, and this can be used as a tool to read the data from *readable streams.

 

Note:

*Readable streams are an abstraction for a source from which data is consumed. (e.g. process.stdin)

 

Why I searched for this module?

To understand the purpose of using this module from JS problem & solving question.

 

To access some data by using readline,

const readline = require('readline');

The following simple example illustrates the basic use of the readline module.

const readline = require('readline');

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

rl.question('What do you think of Node.js? ', (answer) => {
  // TODO: Log the answer in a database
  console.log(`Thank you for your valuable feedback: ${answer}`);

  rl.close();
});

Once this code is invoked, the Node.js application will not terminate until the readline.Interface is closed because the interface waits for data to be received on the input stream.

 

For more detail explanation, see here.

'F2. Problem & Solving > Solving' 카테고리의 다른 글

JS - wrapper object  (0) 2021.07.07
JS - switch  (0) 2021.07.06
[JS] string includes() method  (0) 2021.07.06
Loops - JS algorithm  (0) 2021.06.12
Conditional statements: switch  (0) 2021.06.12