0

Suppose I've prompted the user for input with readline ( in Node ).

Is it possible to access what he types before it's even entered?

Thanks in advance!

Ayoub Rossi
  • 410
  • 5
  • 18
  • Does this answer your question? [Reading value from console, interactively](https://stackoverflow.com/questions/8128578/reading-value-from-console-interactively) – Pronoy999 Oct 12 '20 at 15:11

1 Answers1

0

Switch to the raw mode and you can get one by one when the user presses the key.

var stdin = process.openStdin(); 
require('tty').setRawMode(true);    

stdin.on('keypress', function (chunk, key) {
  process.stdout.write('Get Chunk: ' + chunk + '\n');
  if (key && key.ctrl && key.name == 'c') process.exit();
});
koko-js478
  • 1,703
  • 7
  • 17