# get-stdin

> Get stdin as a string or Uint8Array

Latest version **10.0.0** (published 2026-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-stdin
pnpm add get-stdin
yarn add get-stdin
bun add get-stdin
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 10.0.0 |
| Published | 2026-02-05 |
| First published | 2014-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 349 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | std, stdin, stdio, concat, buffer, stream, process, read |

## Links

- npm: https://www.npmjs.com/package/get-stdin
- Repository: https://github.com/sindresorhus/get-stdin
- Homepage: https://github.com/sindresorhus/get-stdin#readme
- Issues: https://github.com/sindresorhus/get-stdin/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/get-stdin

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 10.0.0 (latest) — 2026-02-05
- 9.0.0 — 2021-04-16
- 8.0.0 — 2020-05-12
- 7.0.0 — 2019-04-15
- 6.0.0 — 2018-03-02
- 5.0.1 — 2015-11-11
- 5.0.0 — 2015-08-31
- 4.0.1 — 2015-01-20
- 4.0.0 — 2015-01-19
- 3.0.2 — 2014-11-23
- 3.0.1 — 2014-11-23
- 3.0.0 — 2014-08-17
- 2.0.0 — 2014-08-14
- 1.0.0 — 2014-08-04
- 0.1.0 — 2014-02-13

## README

# get-stdin

> Get [stdin](https://nodejs.org/api/process.html#process_process_stdin) as a string or `Uint8Array`

## Install

```sh
npm install get-stdin
```

## Usage

```js
// 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:

```js
// example.js
import getStdin from 'get-stdin';

console.log(await getStdin({allowTTY: true}));
//=> 'unicorns'
```

```
$ node example.js
unicorns
<Ctrl+D>
unicorns
```

## API

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).

### getStdin(options?)

Get `stdin` as a `string`.

#### options

Type: `object`

##### allowTTY

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.

##### stdin

Type: `Readable stream`\
Default: `process.stdin`

Stream to read from.

Useful for tests or to read from a custom stream.

### getStdin.buffer(options?)

Get `stdin` as a `Uint8Array`.

#### options

Type: `object`

##### allowTTY

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.

##### stdin

Type: `Readable stream`\
Default: `process.stdin`

Stream to read from.

Useful for tests or to read from a custom stream.

## Tip

You can now accomplish this natively in Node.js using [`streamConsumers.text()`](https://nodejs.org/api/webstreams.html#streamconsumerstextstream) or [`streamConsumers.buffer()`](https://nodejs.org/api/webstreams.html#streamconsumersbufferstream):

```js
// example.js
import {text} from 'node:stream/consumers';

console.log(await text(process.stdin))
//=> 'unicorns'
````

```
$ echo unicorns | node example.js
unicorns
```

## Related

- [get-stream](https://github.com/sindresorhus/get-stream) - Get a stream as a string or buffer

---
_Source: https://npm.io/package/get-stdin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
