1.0.0 • Published 8 years ago

stdin2 v1.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

stdin2 Build status Coverage Status js-standard-style Dependencies devDependencies

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