Reliably get the terminal window size (columns & rows)


Keywords
terminal, size, console, window, width, height, columns, rows, lines, tty, redirected
License
MIT
Install
npm install term-size@2.0.0

Documentation

terminal-size

Reliably get the terminal window size

Because process.stdout.columns doesn't exist when run non-interactively, for example, in a child process or when piped. This module even works when all the TTY file descriptors are redirected!

Confirmed working on macOS, Linux, and Windows.

Install

npm install terminal-size

Usage

import terminalSize from 'terminal-size';

terminalSize();
//=> {columns: 143, rows: 24}

API

terminalSize()

Returns an object with columns and rows properties.