Skip to content

Instantly share code, notes, and snippets.

@RAM92
Created October 27, 2021 16:45
Show Gist options
  • Save RAM92/3bddf6cd7c6b3354eb5c3ab929337aa7 to your computer and use it in GitHub Desktop.
Save RAM92/3bddf6cd7c6b3354eb5c3ab929337aa7 to your computer and use it in GitHub Desktop.
Get input from stdin or filename
#!/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