Answers for "node stdin read char by char"

0

node stdin read char by char

const stdin = process.stdin;
if (!stdin.isTTY) {
  console.log('Error: TTY is not available. (Don\'t start me with nodemon.)');
  process.exit(1);
}
stdin.setRawMode(true);
stdin.setEncoding('utf8');
stdin.resume();

stdin.on('data', (key) => {
  if (key === '\u0003') {
    process.exit();
  } else if (key === '\b') {
    process.stdout.write('\b \b');
  } else if (key === '\r') {
    process.stdout.write('\r\n');
  } else {
    process.stdout.write(key);
  }
});
Posted by: Guest on August-25-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language