Created
April 15, 2019 22:51
-
-
Save chrisdothtml/0ce6c2317af2576dfe0afc885ee21732 to your computer and use it in GitHub Desktop.
Get piped input in nodejs script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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