Last active
October 4, 2023 07:09
-
-
Save wmakeev/59f50f9b333497ee2a819f79032b1660 to your computer and use it in GitHub Desktop.
[Read stdin node.js] #node #stdin #stream
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
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