stdin2

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i stdin2

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • matjaz