// Single place that decides which .env file to load, based on NODE_ENV.
// Import this before anything else reads process.env (server.ts does this first).
import path from "path";
import dotenv from "dotenv";

export const NODE_ENV = process.env.NODE_ENV || "development";

const envFile = path.resolve(process.cwd(), `.env.${NODE_ENV}`);
dotenv.config({ path: envFile });

// Fallback for any var not present in the environment-specific file (e.g. a
// local .env left over from before the split, or a var not yet migrated).
// dotenv.config() never overwrites a var that's already set, so this only
// fills gaps.
dotenv.config({ path: path.resolve(process.cwd(), ".env") });
