1.0.0 • Published 10 years ago
stdin2 v1.0.0
stdin2

Get stdin as a string or buffer, using promise. Supports timeout & tty.
Install
$ npm install --save stdin2Usage
// example.js
const getStdin = require('stdin2')
getStdin().then(str => {
console.log(str)
})$ echo unicorns | node example.js
unicornsUsing 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
1.0.0
10 years ago