-
Notifications
You must be signed in to change notification settings - Fork 0
/
process-utils.ts
40 lines (34 loc) · 1.02 KB
/
process-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export interface ProcessData {
memoryUsage: NodeJS.MemoryUsage;
cpuUsage: NodeJS.CpuUsage;
upTime: number;
version: string;
platform: NodeJS.Platform;
}
export function isTest(): boolean {
return process.env.NODE_ENV === "test";
}
export function isProd(): boolean {
return process.env.NODE_ENV === "production";
}
export function isDev(): boolean {
return process.env.NODE_ENV === "development" || !process.env.NODE_ENV;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function setEnvironment(type: "test" | "production" | "development"): void {
// process.env.NODE_ENV = type;
}
export function getProcessData(): ProcessData {
return {
memoryUsage: process.memoryUsage(),
cpuUsage : process.cpuUsage(),
upTime : process.uptime(),
version : process.version,
platform : process.platform,
};
}
export function setDefaultEnvironment(): void {
if (!process.env.NODE_ENV) {
setEnvironment("development");
}
}