Skip to content

Instantly share code, notes, and snippets.

@chrisdothtml
Created April 15, 2019 22:51
Show Gist options
  • Save chrisdothtml/0ce6c2317af2576dfe0afc885ee21732 to your computer and use it in GitHub Desktop.
Save chrisdothtml/0ce6c2317af2576dfe0afc885ee21732 to your computer and use it in GitHub Desktop.
Get piped input in nodejs script
function getPipedInput () {
return new Promise(resolve => {
let result = ''
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', chunk => (result += chunk))
process.stdin.on('end', () => resolve(result))
})
}
getPipedInput().then(input => {
// ...
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment