
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
Get stdin as a string or
Uint8Array
npm install get-stdin
// example.js
import getStdin from 'get-stdin';
console.log(await getStdin());
//=> 'unicorns'
Run the script with piped input:
$ echo unicorns | node example.js
unicorns
Or run interactively by allowing TTY input and type input, then press Ctrl+D (Unix) or Ctrl+Z (Windows) to signal end of input:
// example.js
import getStdin from 'get-stdin';
console.log(await getStdin({allowTTY: true}));
//=> 'unicorns'
$ node example.js
unicorns
<Ctrl+D>
unicorns
Both methods return a promise that is resolved when the end event fires on the stdin stream, indicating that there is no more data to be read.
By default, in a TTY context the promise resolves with an empty string or Uint8Array. This avoids hanging CLIs that only want piped input and lets them fall back to other input methods. An empty string or Uint8Array means no input was read. To read from a TTY, set allowTTY: true and explicitly close stdin (Ctrl+D on Unix, Ctrl+Z on Windows).
Get stdin as a string.
Type: object
Type: boolean
Default: false
Allow reading from a TTY.
Use this when you want interactive behavior like cat or other Unix filters that wait for EOF even without piped input. The default resolves immediately in a TTY to avoid hanging CLIs that only want piped input and lets them fall back to other input methods.
Type: Readable stream
Default: process.stdin
Stream to read from.
Useful for tests or to read from a custom stream.
Get stdin as a Uint8Array.
Type: object
Type: boolean
Default: false
Allow reading from a TTY.
Use this when you want interactive behavior like cat or other Unix filters that wait for EOF even without piped input. The default resolves immediately in a TTY to avoid hanging CLIs that only want piped input and lets them fall back to other input methods.
Type: Readable stream
Default: process.stdin
Stream to read from.
Useful for tests or to read from a custom stream.
You can now accomplish this natively in Node.js using streamConsumers.text() or streamConsumers.buffer():
// example.js
import {text} from 'node:stream/consumers';
console.log(await text(process.stdin))
//=> 'unicorns'
$ echo unicorns | node example.js
unicorns
The raw-body package is similar to get-stdin but is more focused on parsing HTTP request bodies and provides more options for limiting size, setting character encoding, and handling errors.
Concat-stream is a writable stream that concatenates all the data from a stream and calls a callback with the result. It can be used in a similar way to get-stdin for collecting stream data, but it is not limited to stdin and does not return a promise.
Get-stream is a utility that turns a stream into a string or buffer. It is very similar to get-stdin but works with any stream, not just stdin, and offers more options for handling the stream data.
FAQs
Get stdin as a string or Uint8Array
The npm package get-stdin receives a total of 14,836,638 weekly downloads. As such, get-stdin popularity was classified as popular.
We found that get-stdin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.