mirror of
https://github.com/andwati/order-service.git
synced 2026-11-05 18:32:14 +00:00
feat: add environment configuration and required variables
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
function requireEnv(key: string): string {
|
||||
const value = process.env[key];
|
||||
|
||||
if (!value) {
|
||||
throw new Error(`Environment variable ${key} is required but not set.`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export const env = {
|
||||
nodeEnv: process.env.NODE_ENV ?? "development",
|
||||
port: Number(process.env.PORT) ?? 3000,
|
||||
|
||||
mongoUri: requireEnv("MONGO_URI"),
|
||||
|
||||
jwtSecret: {
|
||||
secret: requireEnv("JWT_SECRET"),
|
||||
expiresIn: process.env.JWT_EXPIRES_IN ?? "1h",
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user