Created
August 11, 2023 16:03
-
-
Save stefanocudini/2dba66da660e4888a919d684574f9481 to your computer and use it in GitHub Desktop.
read stdin in nodejs
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
let rawInput = ''; | |
process.stdin.on('readable', function() { | |
const chunk = process.stdin.read(); | |
if (chunk !== null) { | |
rawInput += chunk; | |
} | |
}); | |
process.stdin.on('end', function() { | |
const converted = convert(rawInput); | |
if (!converted) { | |
exit(); | |
} | |
process.stdout.write(`${JSON.stringify(converted)}\n`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment