nodejs get single character from sdin code example
Example: 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);
}
});