diff --git a/src/a.ts b/src/a.ts index 7d3f1ec..79ef0a4 100644 --- a/src/a.ts +++ b/src/a.ts @@ -1 +1,3 @@ -console.log(`M365:${process.env.M365_USERNAME}`); \ No newline at end of file +import { Env } from "./env"; +console.log(`M365:${process.env.M365_USERNAME}`); +console.log(`M365B:${Env.username}`); \ No newline at end of file diff --git a/src/env.ts b/src/env.ts new file mode 100644 index 0000000..e57e512 --- /dev/null +++ b/src/env.ts @@ -0,0 +1,15 @@ +import * as dotenv from "dotenv"; +dotenv.config(); + +export class Env { + public static get username() { + return this.getVal("M365_USERNAME", process.env.M365_USERNAME); + } + + private static getVal(name: string, value: string | undefined): string { + if (!value) { + throw new Error(`Environment variable ${name} should not be empty.`); + } + return value as string; + } +} \ No newline at end of file