Skip to content

Commit 8d24698

Browse files
committed
fix(server): crash early if required env vars are missing
1 parent 3f601cf commit 8d24698

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

backend/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#SESSION_SECRET=your_secret_here
2+
MONGO_URI=mongodb://localhost:27017/github_tracker
3+
PORT=5000

backend/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const app = express();
1616
// CORS configuration
1717
app.use(cors('*'));
1818

19+
const REQUIRED_ENV = ['SESSION_SECRET', 'MONGO_URI'];
20+
21+
for (const key of REQUIRED_ENV) {
22+
if (!process.env[key]) {
23+
console.error(`[startup] Missing required environment variable: ${key}`);
24+
process.exit(1);
25+
}
26+
}
27+
1928
// Middleware
2029
app.use(bodyParser.json());
2130
app.use(session({

0 commit comments

Comments
 (0)