Skip to content

Commit 1e0384f

Browse files
committed
feat: add environment variable validation on backend startup
1 parent 392c8a3 commit 1e0384f

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

backend/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
import "dotenv/config";
2+
3+
const REQUIRED_ENV_VARS = ["DATABASE_URL", "DIRECT_URL"];
4+
5+
for (const key of REQUIRED_ENV_VARS) {
6+
if (!process.env[key]) {
7+
console.error(`[startup] Missing required environment variable: ${key}`);
8+
console.error("Check backend/.env.example for the full list of required variables.");
9+
process.exit(1);
10+
}
11+
}
12+
213
import { app } from "./app.js";
314

415
const port = Number(process.env.PORT ?? 4000);

0 commit comments

Comments
 (0)