Node.js v26.10.0 documentation
- Node.js v26.10.0
- Table of contents
- TTY
- Class:
tty.ReadStream - Class:
tty.WriteStreamnew tty.ReadStream(fd[, options])new tty.WriteStream(fd)- Event:
'resize' writeStream.clearLine(dir[, callback])writeStream.clearScreenDown([callback])writeStream.columnswriteStream.cursorTo(x[, y][, callback])writeStream.getColorDepth([env])writeStream.getWindowSize()writeStream.hasColors([count][, env])writeStream.isTTYwriteStream.moveCursor(dx, dy[, callback])writeStream.rows
tty.isatty(fd)
- Class:
- TTY
- Index
- About this documentation
- Usage and example
- Assertion testing
- Asynchronous context tracking
- Async hooks
- Benchmark runner
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Environment Variables
- Errors
- Events
- File system
- FFI
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Iterable Streams API
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Modules: TypeScript
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Single executable applications
- SQLite
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- Virtual File System
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- Other versions
- Options
TTY#
Stability: 2 - Stable
The node:tty module provides the tty.ReadStream and tty.WriteStream
classes. In most cases, it will not be necessary or possible to use this module
directly. However, it can be accessed using:
const tty = require('node:tty');
When Node.js detects that it is being run with a text terminal ("TTY")
attached, process.stdin will, by default, be initialized as an instance of
tty.ReadStream and both process.stdout and process.stderr will, by
default, be instances of tty.WriteStream. The preferred method of determining
whether Node.js is being run within a TTY context is to check that the value of
the process.stdout.isTTY property is true:
$ node -p -e "Boolean(process.stdout.isTTY)"
true
$ node -p -e "Boolean(process.stdout.isTTY)" | cat
false
In most cases, there should be little to no reason for an application to
manually create instances of the tty.ReadStream and tty.WriteStream
classes.
Class: tty.ReadStream#
- Extends:
<net.Socket>
Represents the readable side of a TTY. In normal circumstances
process.stdin will be the only tty.ReadStream instance in a Node.js
process and there should be no reason to create additional instances.
readStream.isRaw#
A boolean that is true if the TTY is currently configured to operate as a
raw device.
This flag is always false when a process starts, even if the terminal is
operating in raw mode. Its value will change with subsequent calls to
setRawMode.
readStream.isTTY#
A boolean that is always true for tty.ReadStream instances.
readStream.setRawMode(mode)#
mode<boolean>|<string>Iftrueor'raw', configures thetty.ReadStreamto operate as a raw device. If'io', configures thetty.ReadStreamto operate in binary-safe I/O mode. Iffalse, configures thetty.ReadStreamto operate in its default mode. ThereadStream.isRawproperty will be set to whether the stream is in raw mode, and thereadStream.rawModeproperty will be set to the resulting mode.- Returns:
<this>The read stream instance.
Allows configuration of tty.ReadStream so that it operates as a raw device.
When in raw mode, input is always available character-by-character, not
including modifiers. Additionally, all special processing of input characters
by the terminal is disabled, including echoing input
characters. Ctrl+C will no longer cause a SIGINT when
in this mode. This mode does not affect terminal output processing, such as
newline translation on Unix terminals.
On Windows, setRawMode() requires write permission to the console input
buffer. When opening "\\\\.\\CONIN$" with the fs.open() family of APIs
(for passing into new tty.ReadStream()), be sure to use a read/write flag
such as 'r+'.
When in binary-safe I/O mode, terminal output processing is also disabled.
This corresponds to libuv's UV_TTY_MODE_IO mode and is not supported on
Windows.
readStream.rawMode#
The current raw mode for the