Skip to content

Commit

Permalink
Document native alternative
Browse files Browse the repository at this point in the history
Fixes #36
  • Loading branch information
sindresorhus committed Oct 15, 2023
1 parent 6ce9966 commit 804fd65
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
## Install

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

## Usage
Expand Down Expand Up @@ -39,18 +39,23 @@ Get `stdin` as a `Buffer`.

In a TTY context, a promise that resolves to an empty `Buffer` is returned.

## 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(stream))
//=> 'unicorns'
````

```
$ echo unicorns | node example.js
unicorns
```
## Related
- [get-stream](https://github.com/sindresorhus/get-stream) - Get a stream as a string or buffer

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-get-stdin?utm_source=npm-get-stdin&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>

0 comments on commit 804fd65

Please sign in to comment.