Skip to content

Commit 917ef69

Browse files
committed
Refactor: refactor get NODE_ENV
1 parent c77abad commit 917ef69

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/common/helper/env.helper.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@ import { NODE_ENVIRONMENT } from './env.validation';
44

55
export const getNodeEnv = (() => {
66
const env = process.env.NODE_ENV;
7-
8-
switch (env) {
9-
case 'test':
10-
return NODE_ENVIRONMENT.test;
11-
case 'development':
12-
return NODE_ENVIRONMENT.development;
13-
case 'stage':
14-
return NODE_ENVIRONMENT.stage;
15-
case 'production':
16-
return NODE_ENVIRONMENT.production;
17-
default:
18-
throw new InternalServerErrorException('Unknown NODE_ENV');
7+
const nodeEnv = NODE_ENVIRONMENT[env];
8+
if (nodeEnv === undefined) {
9+
throw new InternalServerErrorException('Unknown NODE_ENV');
1910
}
11+
return nodeEnv;
2012
})();
2113

2214
export const isIgnoreEnvFile =

src/common/helper/env.validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const NODE_ENVIRONMENT = {
1818
[stage]: stage,
1919
[production]: production,
2020
[test]: test,
21-
};
21+
} as const;
2222

2323
export class EnvironmentVariables {
2424
@IsEnum(NODE_ENVIRONMENT)

0 commit comments

Comments
 (0)