/** * Load environment variables from '.env' file */ loadEnvFile() { if (this.flags.env || this.flags.envfile) { try { const dotenv = require("dotenv"); if (this.flags.envfile) dotenv.config({ path: this.flags.envfile }); else dotenv.config(); } catch(err) { throw new Error("The 'dotenv' package is missing! Please install it with 'npm install dotenv --save' command."); } } }
dotenvFiles.forEach((dotenvFile) => { if (fs.existsSync(dotenvFile)) { dotenvExpand(dotenv.config({ path: dotenvFile })); } });
dotenv() { const env = dotenv.config() return env }
configPaths.filter(fs.existsSync).forEach(path => { console.log('Loading env file:', path); dotenv.config({ path }); });
public loadConfig(): void { // 避免重复加载 if (this.cache) { return; } // 如果是生产环境,一些所需的信息会通过CI工具注入到process.env中 if (this.mode === 'production') { this.cache = process.env; return; } // 本地开发环境,需要读取项目目录中的 .env 文件 const filepath = path.join(__dirname, '..', '.env'); if (!fs.existsSync(filepath)) { throw new Error(`Please create configuration file: ${filepath}`); } const localEnv = dotenv.config({ path: filepath }).parsed; this.cache = { ...process.env, ...localEnv, }; }
public loadConfig(): void { // 避免重复加载 if (this.cache) { return; } // 如果是生产环境,一些所需的信息会通过CI工具注入到process.env中 if (this.mode === 'production') { this.cache = process.env; return; } // 本地开发环境,需要读取项目目录中的 .env 文件 const filepath = path.join(__dirname, '..', '.env'); if (!fs.existsSync(filepath)) { throw new Error(`Please create configuration file: ${filepath}`); } const localEnv = dotenv.config({ path: filepath }).parsed; this.cache = { ...process.env, ...localEnv, }; }