Created
October 27, 2021 16:45
-
-
Save RAM92/3bddf6cd7c6b3354eb5c3ab929337aa7 to your computer and use it in GitHub Desktop.
Get input from stdin or filename
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
#!/usr/bin/env node | |
const fs = require('fs'); | |
function getInput() { | |
if (process.stdin.isTTY) { | |
const inputFileName = process.argv[2]; | |
return fs.readFileSync(inputFileName, {encoding: 'utf8'}); | |
} else { | |
return fs.readFileSync(0, {encoding: 'utf8'}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment