Created
June 16, 2023 07:03
-
-
Save johandalabacka/417dbcaa1f99fc967fa035da374548cf to your computer and use it in GitHub Desktop.
Read and return all of stdin in node
This file contains hidden or 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 readStdin () { | |
return new Promise((resolve, reject) => { | |
process.stdin.resume() | |
process.stdin.setEncoding('utf8') | |
let buffer = '' | |
process.stdin.on('data', (chunk) => { | |
buffer += chunk | |
}) | |
process.stdin.on('error', (err) => { | |
reject(err) | |
}) | |
process.stdin.on('end', () => { | |
resolve(buffer) | |
}) | |
}) | |
} | |
const input = await readStdin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment