We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 50117a2 commit 998fcc9Copy full SHA for 998fcc9
src/a.ts
@@ -1 +1,3 @@
1
-console.log(`M365:${process.env.M365_USERNAME}`);
+import { Env } from "./env";
2
+console.log(`M365:${process.env.M365_USERNAME}`);
3
+console.log(`M365B:${Env.username}`);
src/env.ts
@@ -0,0 +1,15 @@
+import * as dotenv from "dotenv";
+dotenv.config();
+
4
+export class Env {
5
+ public static get username() {
6
+ return this.getVal("M365_USERNAME", process.env.M365_USERNAME);
7
+ }
8
9
+ private static getVal(name: string, value: string | undefined): string {
10
+ if (!value) {
11
+ throw new Error(`Environment variable ${name} should not be empty.`);
12
13
+ return value as string;
14
15
+}
0 commit comments