feat: get env variables safely

This commit is contained in:
karishmas6
2024-10-05 15:53:10 +05:30
parent b45b6e0692
commit 09b6c9c265

8
server/src/utils/env.ts Normal file
View File

@@ -0,0 +1,8 @@
// Helper function to get environment variables and throw an error if they are not set
export const getEnvVariable = (key: string, defaultValue?: string): string => {
const value = process.env[key] || defaultValue;
if (!value) {
throw new Error(`Environment variable ${key} is not defined`);
}
return value;
};