Skip to content

Commit 82d89ff

Browse files
committed
refactor: reorganize loadEnvFile function to ensure environment-specific configurations are loaded correctly
1 parent 171efcd commit 82d89ff

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/loadEnvFile.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ function loadEnvFile(filePath: string) {
3636
const nodeEnv = process.env.NODE_ENV || 'development';
3737
console.log(`🌍 Environment: ${nodeEnv}`);
3838

39-
// Load environment-specific config first (public values, production only)
40-
if (nodeEnv === 'production') {
41-
const envFile = join(process.cwd(), '.env.production');
42-
loadEnvFile(envFile);
43-
}
44-
45-
// Load .env file with secrets and local config (overrides public config if any)
46-
// Required for DISCORD_TOKEN and other secrets
47-
const localEnvFile = join(process.cwd(), '.env');
48-
loadEnvFile(localEnvFile);
49-
5039
if (nodeEnv === 'test') {
5140
console.log('🧪 Loading test environment variables');
5241
const testEnvFile = join(process.cwd(), '.env.test');
5342
loadEnvFile(testEnvFile);
43+
} else {
44+
// Load environment-specific config first (public values, production only)
45+
if (nodeEnv === 'production') {
46+
const envFile = join(process.cwd(), '.env.production');
47+
loadEnvFile(envFile);
48+
}
49+
50+
// Load .env file with secrets and local config (overrides public config if any)
51+
// Required for DISCORD_TOKEN and other secrets
52+
const localEnvFile = join(process.cwd(), '.env');
53+
loadEnvFile(localEnvFile);
5454
}

0 commit comments

Comments
 (0)