: 입력, 한 줄(엔터까지엔터까지)을 읽어 온다.
1줄 받아오기
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', (input) => {
console.log(`Received: ${input}`);
});
2줄 받아오기
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input.push(line);
if(input.length >= 2)
rl.close();
}).on('close', function () {
console.log(input);
process.exit();
});
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
let count = 0;
rl.on('line', function (line) {
input.push(line);
// :: 입력 제한 관리
count++;
if(count >= 2)
rl.close();
}).on('close', function () {
console.log(input);
process.exit();
});
>> 좀 더 직관적으로 만들어 본 코드