Reading multiple lines from stdin

Reading multiple lines from stdin
0.0 0

#1

I have a need to read to lines of input from stdin.
Something like this.

10
2 5 12 17 95

So far I have the following code:

var readline = require('readline');

process.stdin.setEncoding('utf8');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: true
});

const numbers = [];

rl.on('line', (input) => {
  numbers.push(input);
  rl.close();
}).on('close', () => console.log('numbers'));

Which reads the first line fine but then runs rl.close() and ends.
I need to terminate after reading two (and only two) lines of input (with no other terminating characters) I’ve tried moving rl.close() out of the callback that allows me to read in multiple lines but then I don’t see how to start the close event.

This sort of works for small inputs.

var readline = require('readline');

process.stdin.setEncoding('utf8');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: true
});

const cmdlInput = [];

rl.on('line', (line) => {
  line !== '' ? cmdlInput.push(line): rl.close();
}).on('close', () => {
const size = cmdlInput.shift();
const numArray = cmdlInput.shift().split(' ');
console.log(numArray)
});

But for large values It’s talking too long and often times out. Is there a better way to input long string values from the command line?