Get stdin as a string or buffer
This fork of the original project includes support for reading stdin from TTY, not only via pipes.
$ npm install @prantlf/get-stdin-with-tty
// example.js
const getStdin = require('@prantlf/get-stdin-with-tty');
(async () => {
console.log(await getStdin({ tty: true }));
//=> 'unicorns'
})();
$ echo unicorns | node example.js
unicorns
Both 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.
Get stdin
as a string
.
In a TTY context, a promise that resolves to an empty string is returned, unless options.tty
or getStdin.tty
is true.
Get stdin
as a Buffer
.
In a TTY context, a promise that resolves to an empty Buffer
is returned.
Set global TTY handling. When true, accepts input from TTY until a new line beginning with Ctrl-d or Ctrl-z (ASCII 04 and 26) is entered. (default = true
)
When enabled for the example above:
$ node example.js
foobar
barfoo
^d
// =>
foobar
barfoo
- get-stream - Get a stream as a string or buffer
MIT © Sindre Sorhus © Moos © Ferdinand Prantl