Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js TTY Module

Node.js TTY Module

Posted on October 14, 2025October 14, 2025 By Rishabh saini No Comments on Node.js TTY Module

Node.js TTY Module

The Node.js TTY (Teletype) module provides an interface for controlling and interacting with terminal-based input and output. It includes two important classes — tty.ReadStream and tty.WriteStream. While in most cases developers don’t need to use this module directly, understanding how it works is helpful when building CLI (Command Line Interface) applications or interactive terminal tools.

Introduction to Applied AI:–Click Here

Accessing the TTY Module

To use the TTY module, include it in your project using the require() method:

var tty = require('tty');

When Node.js runs inside a TTY context, the following happens automatically:

  • process.stdin becomes an instance of tty.ReadStream
  • process.stdout becomes an instance of tty.WriteStream

Data Science Tutorial:-Click Here

You can check whether your Node.js process is running inside a TTY environment using this command:

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

If the output is true, it means your Node.js process is connected to a terminal.

Class: ReadStream

The ReadStream class is a subclass of net.Socket and represents the readable portion of a TTY. In most cases, process.stdin is the only instance of tty.ReadStream when isatty(0) returns true.

Key Properties and Methods

Download New Real Time Projects :–Click here

  • rs.isRaw:
    A Boolean property initialized to false. It indicates whether the TTY stream is currently in raw mode.
  • rs.setRawMode(mode):
    Accepts a Boolean value (true or false). When set to true, it enables raw mode — meaning input data is read byte-by-byte without line buffering or interpretation. This is commonly used for reading keypresses directly.

Example:

process.stdin.setRawMode(true);

Class: WriteStream

The WriteStream class, also a subclass of net.Socket, represents the writable portion of a TTY. Typically, process.stdout is the only instance of tty.WriteStream when isatty(1) returns true.

Machine Learning Tutorial:–Click Here

The resize Event

A resize event is emitted whenever the terminal window size changes — that is, when the number of rows or columns updates.

Example:

process.stdout.on('resize', () => {
  console.log('Screen size has changed!');
  console.log(`${process.stdout.columns}x${process.stdout.rows}`);
});

Additional Properties

Complete Advance AI topics:- CLICK HERE

  • ws.columns: Returns the number of columns in the current terminal window.
  • ws.rows: Returns the number of rows in the current terminal window.
    Both of these properties update dynamically on terminal resize.

Example: Node.js TTY Implementation

File: tty.js

var tty = require('tty');  

process.stdin.setRawMode(true);  
process.stdin.resume();  
console.log('I am leaving now');  

process.stdin.on('keypress', function(char, key) {  
  if (key && key.ctrl && key.name == 'c') {  
    process.exit();  
  }  
});

Output:

When you run this script and press Ctrl + C, the process will exit immediately — demonstrating how setRawMode(true) allows for real-time key detection.

Deep Learning Tutorial:– Click Here
Complete Python Course with Advance topics:-Click Here
SQL Tutorial :–Click Here


node js tty module tutorial
node js tty module github
node js tty module example
node js exit codes
fs module in node js
process stdout istty
utility modules in node js
processticksandrejections node js

 

    Post Views: 266
    Node.js Tutorial Tags:core module, deno vs nodejs, denojs vs nodejs, detect keypress nodejs, fs module, how to detect keypress nodejs, http module, keypress nodejs, keypress nodejs event, module, node js modules, node module 사용, node modules, nodejs, nodejs apis, nodejs core modules, nodejs course, nodejs how to detect keypress, nodejs installation, nodejs keypress, nodejs readline, nodejs routes, nodejs training, nodejs tutorials, nodejs 모듈, nodejs 설치, readline module, readline nodejs, tty module

    Post navigation

    Previous Post: Node.js Punycode
    Next Post: Node.js Web Module

    More Related Articles

    Node.js MySQL Create Database Node.js MySQL Create Database Node.js Tutorial
    Node.js Package ManagerNode.js Package Manager Node.js Package Manager Node.js Tutorial
    Node.js DNS module Node.js DNS module Node.js Tutorial

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. News Portal Project in PHP and MySql Free Source Code
    5. Flipkart Clone using PHP And MYSQL Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Online Bike Rental Management System Using PHP and MySQL
    9. E learning Website in php with Free source code
    10. E-Commerce Website Project in Java Servlets (JSP)
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL
    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
    • Online Job Portal System in JSP Servlet MySQL

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme