Files
flyer-crawler.projectium.com/preload.ts
Torben Sorensen 33b1800f72
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m30s
ugh
2025-12-02 18:43:49 -08:00

19 lines
702 B
TypeScript

// 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);
}