Node.js TTY

The Node.js TTY module contains tty.ReadStream and tty.WriteStream classes. Much of the time, there is no compelling reason to utilize this module simple.

You need to utilize require ('tty') to get to this module.


  1. var tty = require('tty');  

When Node.js finds that it is being kept running inside a TTY setting, then:

  • process.stdin will be a tty.ReadStream occurrence
  • process.stdout will be a tty.WriteStream instance

To check that if Node.js is running in a TTY context, use the following command:

  1. node -p -e "Boolean(process.stdout.isTTY)"  

Node.js TTY Example

File: tty.js

  1. var tty = require('tty');  
  2. process.stdin.setRawMode(true);  
  3. process.stdin.resume();  
  4.  console.log('I am leaving now');  
  5. process.stdin.on('keypress', function(char, key) {  
  6.   if (key && key.ctrl && key.name == 'c') {  
  8.     process.exit()  
  9.   }  
  10. });  

welookups is optimized for learning.© welookups. 2018 - 2020 All Right Reserved and you agree to have read and accepted our term and condition.