File size: 908 Bytes
1a25764
 
 
 
1f0f638
1a25764
 
 
 
 
 
 
 
 
1f0f638
1a25764
 
 
 
 
 
 
 
 
1f0f638
1a25764
1f0f638
1a25764
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';

const path = require('path');

/* v8 ignore start — module-level CJS require not tracked by V8 */
function loadEnv() {
  const env = (process.env.NODE_ENV || 'development').toLowerCase();
  if (env === 'production') return;
  const envFileMap = {
    development: ['.env', '.env.dev', '.env.development'],
    'production-local': ['.env.prod', '.env.production'],
    test: ['.env.test'],
  };
  const envFiles = envFileMap[env] || envFileMap.development;
  const rootDir = path.join(__dirname, '..', '..');
  for (const file of envFiles) {
    const fullPath = path.join(rootDir, file);
    const { error } = require('dotenv').config({ path: fullPath, override: false });
    if (error) {
      if (error.code === 'ENOENT') continue;
      console.error(`[dotenv] Error loading ${file}:`, error.message);
    }
  }
}
/* v8 ignore stop */

/* v8 ignore next */
module.exports = { loadEnv };