The readline module provides an interface for reading data from a Readable stream (such as process.stdin) one line at a time. It can be accessed using:
const readline = require('readline');
readline( ) is their method to read stdin
print( ) is the stdout method.
Number( ) => double, integer 구분해준다.
parseInt( ) => only integer
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.
If you come from web, you could almost compare readline to prompt(),
the script simply pauses and waits until something comes from user input.
'TIL > TIL' 카테고리의 다른 글
React set up (0) | 2020.03.04 |
---|---|
AJAX *helpful (0) | 2020.02.23 |
Prototype (0) | 2020.02.23 |
Event Loop & heap & stack (0) | 2020.02.23 |
비동기, 서버요청, this (0) | 2020.02.23 |
comment