UNPKG

1.27 kBMarkdownView Raw
1# get-stdin
2
3> Get [stdin](https://nodejs.org/api/process.html#process_process_stdin) as a string or buffer
4
5## Install
6
7```
8$ npm install get-stdin
9```
10
11## Usage
12
13```js
14// example.js
15import getStdin from 'get-stdin';
16
17console.log(await getStdin());
18//=> 'unicorns'
19```
20
21```
22$ echo unicorns | node example.js
23unicorns
24```
25
26## API
27
28Both methods returns a promise that is resolved when the `end` event fires on the `stdin` stream, indicating that there is no more data to be read.
29
30### getStdin()
31
32Get `stdin` as a `string`.
33
34In a TTY context, a promise that resolves to an empty `string` is returned.
35
36### getStdin.buffer()
37
38Get `stdin` as a `Buffer`.
39
40In a TTY context, a promise that resolves to an empty `Buffer` is returned.
41
42## Related
43
44- [get-stream](https://github.com/sindresorhus/get-stream) - Get a stream as a string or buffer
45
46---
47
48<div align="center">
49 <b>
50 <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>
51 </b>
52 <br>
53 <sub>
54 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
55 </sub>
56</div>