stdin2
v1.0.0
Published
Get stdin as a string or buffer, using promise. Supports timeout & tty.
Downloads
5
Maintainers
Readme
stdin2
Get stdin as a string or buffer, using promise. Supports timeout & tty.
Install
$ npm install --save stdin2
Usage
// example.js
const getStdin = require('stdin2')
getStdin().then(str => {
console.log(str)
})
$ echo unicorns | node example.js
unicorns
Using ES7 await
import getStdin from 'stdin2'
(async function () {
try {
console.log(await getStdin())
} catch (e) {
console.error(e)
}
})()
API
Function 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.
getStdin([options])
Get stdin
as a string.
Options
- buffer (false) - returns buffer instead of a string
- timeout (Infinity) - rejects after miliseconds, if no data is read
- rejectTTY (false) - rejects if program is run in TTY
License
MIT