// preload.ts /** * This script is preloaded using Node's --require flag. * Its purpose is to load the correct environment file (.env or .env.test) * before any other application code runs. This ensures that `process.env` * is populated correctly for the given environment (production vs. testing). */ import dotenv from 'dotenv'; import path from 'path'; // Determine which .env file to load based on the NODE_ENV variable. const envFile = process.env.NODE_ENV === 'test' ? '.env.test' : '.env'; const envPath = path.resolve(process.cwd(), envFile); const result = dotenv.config({ path: envPath }); if (result.error) { console.error(`[preload.ts] Error loading ${envFile}:`, result.error); }