-
Notifications
You must be signed in to change notification settings - Fork 0
/
envs.ts
29 lines (23 loc) · 799 Bytes
/
envs.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
import * as dotenv from 'dotenv';
import * as z from 'zod';
const dotenvConfigOutput = dotenv.config({
path: process.env.NODE_ENV === 'testing' ? '.env.testing' : '.env',
});
if (dotenvConfigOutput.error) {
throw dotenvConfigOutput.error;
}
const { parsed: envVariables } = dotenvConfigOutput;
const environmentSchema = z.object({
PORT: z.string().default('3001'),
NODE_ENV: z
.enum(['development', 'production', 'testing'])
.default('development'),
DB_NAME: z.string().min(1),
SECRET: z.string().min(1),
REDIS_HOST: z.string().min(1),
REDIS_PORT: z.string().default('6379'),
ADMIN_USERNAME: z.string().min(1),
ADMIN_PASSWORD: z.string().min(1),
});
const getParsedEnvVariables = () => environmentSchema.parse(envVariables);
export default getParsedEnvVariables();