Skip to content

Commit 998fcc9

Browse files
committed
test
1 parent 50117a2 commit 998fcc9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/a.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
console.log(`M365:${process.env.M365_USERNAME}`);
1+
import { Env } from "./env";
2+
console.log(`M365:${process.env.M365_USERNAME}`);
3+
console.log(`M365B:${Env.username}`);

src/env.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as dotenv from "dotenv";
2+
dotenv.config();
3+
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

Comments
 (0)