Skip to content

Commit

Permalink
chore: added validation schema and imported dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
pratham-outside committed Dec 29, 2024
1 parent 81a71f0 commit b3e172f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { z } from 'zod';
export const envVariables = {
import { config } from 'dotenv';
config();
export const env = {
POSTGRES_DB: process.env.POSTGRES_DB,
POSTGRES_USER: process.env.POSTGRES_USER,
POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD,
Expand All @@ -13,7 +15,7 @@ export const envVariables = {
EMAIL_PORT: +(process.env.EMAIL_PORT || 587),
} as const;

enum APP_ENVIRONVENT {
export enum APP_ENVIRONVENT {
DEVELOPMENT = 'development',
PRODUCTION = 'production',
}
Expand All @@ -39,8 +41,10 @@ const validationSchema = z
})
.required();

export const validate = (): object => {
const value = validationSchema.safeParse(envVariables);
type ValidationSchema = z.infer<typeof validationSchema>;

export const validate = (): ValidationSchema => {
const value = validationSchema.safeParse(env);
if (!value.success) {
throw new Error(`---${value.error.issues[0].path} :: ${value.error.issues[0].message.toUpperCase()}---`);
}
Expand Down

0 comments on commit b3e172f

Please sign in to comment.