Created Frontend and backend server and using claude to deploy db.ts and env.ts
This commit is contained in:
0
server/src/config/db.ts
Normal file
0
server/src/config/db.ts
Normal file
21
server/src/config/env.ts
Normal file
21
server/src/config/env.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import dotenv from "dotenv"
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
||||
// This function validates that required env vars exist at startup
|
||||
// Your app crashes immediately with a clear message — not silently later
|
||||
const getEnvVar = (key: string): string => {
|
||||
const value = process.env[key];
|
||||
if (!value) {
|
||||
throw new Error(`Missing required Environment Variable: ${key}`)
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export const ENV = {
|
||||
PORT: process.env.PORT || '5000',
|
||||
MONGO_URI: getEnvVar('MONGO_URI'),
|
||||
JWT_SECRET: getEnvVar('JWT_SECRET'),
|
||||
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||
}
|
||||
Reference in New Issue
Block a user