diff --git a/server.ts b/server.ts index a117d322..4f7f7045 100644 --- a/server.ts +++ b/server.ts @@ -12,8 +12,13 @@ import userRouter from './src/routes/user'; import adminRouter from './src/routes/admin'; import aiRouter from './src/routes/ai'; -// Load environment variables from a .env file at the root of your project -dotenv.config(); +// Conditionally load environment variables based on the environment. +// When running tests, `NODE_ENV` is automatically set to 'test' by Vitest. +if (process.env.NODE_ENV === 'test') { + dotenv.config({ path: '.env.test' }); +} else { + dotenv.config(); // Load the default .env file for development/production +} const app = express();