Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active September 30, 2022 23:28
Show Gist options
  • Save antklim/0f81e517cb7361aeded3c4394f9b015a to your computer and use it in GitHub Desktop.
Save antklim/0f81e517cb7361aeded3c4394f9b015a to your computer and use it in GitHub Desktop.
const readFile = async (file: string): Promise<[Error | null, string]> => {
try {
const text = await Deno.readTextFile(file);
return [null, text];
} catch (err) {
return [err, ""];
}
};
const main = async () => {
const file = Deno.env.get("FILE");
if (!file) {
console.log("file name required.");
return;
}
console.log(`reading ${file} ...`);
const [err, text] = await readFile(file);
if (err != null) {
console.error(`failed to read ${file}: ${err}`);
return;
}
console.log(`file content:\n${text}`);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment