Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created August 11, 2023 16:03
Show Gist options
  • Save stefanocudini/2dba66da660e4888a919d684574f9481 to your computer and use it in GitHub Desktop.
Save stefanocudini/2dba66da660e4888a919d684574f9481 to your computer and use it in GitHub Desktop.
read stdin in nodejs
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