A Node.js utility to read stdin as a string or Uint8Array with TTY handling.
get-stdin is a Node.js library that provides a simple, promise-based way to read data from standard input (stdin) as a string or Uint8Array. It solves the problem of handling stdin in both piped and interactive terminal scenarios, abstracting away stream complexities and TTY edge cases. The module is designed for CLI tools and scripts that need to process input from pipes or user interaction.
Node.js developers building command-line interfaces (CLIs), scripts, or tools that require reading piped input or interactive terminal input. It's particularly useful for those creating Unix-like filters or utilities that process stdin.
Developers choose get-stdin for its minimal API, reliable TTY handling, and lightweight design. It simplifies stdin reading compared to native Node.js stream methods, offering clear options for interactive use and avoiding common pitfalls like hanging CLIs.
Get stdin as a string or buffer
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
get-stdin returns a promise that resolves when stdin ends, abstracting away stream event listeners and simplifying asynchronous code, as shown in the clean usage examples.
It intelligently defaults to avoiding hanging in TTY contexts, with an `allowTTY` option for interactive input, making it reliable for both piped and terminal use cases.
Supports reading stdin as both string and Uint8Array via `getStdin()` and `getStdin.buffer()`, catering to different data types without extra configuration.
Allows specifying a custom readable stream via the `stdin` option, useful for testing or alternative input sources, as documented in the API.
The README admits modern Node.js offers `streamConsumers.text()` and `buffer()` as built-in alternatives, making get-stdin less essential and adding dependency overhead.
It only handles stdin reading; for general stream reading, users must rely on a separate library like get-stream, which can complicate dependency management.
Focuses solely on reading input without built-in parsing, validation, or transformation features, requiring additional code for complex use cases.