Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active September 30, 2022 23:31
Show Gist options
  • Select an option

  • Save antklim/9fcb332ded89a0f75adba79bdab185c8 to your computer and use it in GitHub Desktop.

Select an option

Save antklim/9fcb332ded89a0f75adba79bdab185c8 to your computer and use it in GitHub Desktop.
const readFile = async (file: string): Promise<string | Error> => {
try {
return await Deno.readTextFile(file);
} 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 text = await readFile(file);
if (text instanceof Error) {
console.error(`failed to read ${file}: ${text}`);
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