Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active October 4, 2023 07:09
Show Gist options
  • Save wmakeev/59f50f9b333497ee2a819f79032b1660 to your computer and use it in GitHub Desktop.
Save wmakeev/59f50f9b333497ee2a819f79032b1660 to your computer and use it in GitHub Desktop.
[Read stdin node.js] #node #stdin #stream
import assert from "node:assert";
import { readFileSync } from "node:fs";
let inputText;
try {
inputText = readFileSync(process.stdin.fd, "utf-8");
} catch (err) {
assert.ok(err instanceof Error);
// Empty input?
if ("code" in err && err.code === "EAGAIN") {
process.exit(0);
}
throw err;
}
console.log(inputText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment