Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hellyzh committed Nov 21, 2022
1 parent 50117a2 commit 998fcc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/a.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
console.log(`M365:${process.env.M365_USERNAME}`);
import { Env } from "./env";
console.log(`M365:${process.env.M365_USERNAME}`);
console.log(`M365B:${Env.username}`);
15 changes: 15 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 998fcc9

Please sign in to comment.