Skip to content

Instantly share code, notes, and snippets.

@johandalabacka
Created June 16, 2023 07:03
Show Gist options
  • Save johandalabacka/417dbcaa1f99fc967fa035da374548cf to your computer and use it in GitHub Desktop.
Save johandalabacka/417dbcaa1f99fc967fa035da374548cf to your computer and use it in GitHub Desktop.
Read and return all of stdin in node
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