I am trying to understand process.stdin.
For example, I need to show array elements in the console. And I have to let the user choose which item will be shown.
I have a code:
var arr = ['elem1','elem2','elem3','elem4','elem5'], lastIndx = arr.length-1; showArrElem(); function showArrElem () { console.log('press number from 0 to ' + lastIndx +', or "q" to quit'); process.stdin.on('readable', function (key) { var key = process.stdin.read(); if (!process.stdin.isRaw) { process.stdin.setRawMode( true ); } else { var i = String(key); if (i == 'q') { process.exit(0); } else { console.log('you press ' +i);
Why is "i" null when I dial a second time? How to use "process.stdin.on"?
source share