import dotenv from 'dotenv'; import { Environment } from '../types'; // Load environment variables from .env file dotenv.config(); export interface Config { port: number; nodeEnv: Environment; logLevel: 'error' | 'warn' | 'info' | 'debug'; } // Validate and export environment configuration export const config: Config = { port: Number(process.env.PORT) || 3000, nodeEnv: (process.env.NODE_ENV as Environment) || 'development', logLevel: (process.env.LOG_LEVEL as Config['logLevel']) || 'info' }; // Validate required environment variables if (!config.port || isNaN(config.port)) { throw new Error('Invalid PORT configuration'); } if (!['development', 'staging', 'production'].includes(config.nodeEnv)) { throw new Error('Invalid NODE_ENV configuration'); } if (!['error', 'warn', 'info', 'debug'].includes(config.logLevel)) { throw new Error('Invalid LOG_LEVEL configuration'); }