mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-10-13 18:22:13 +08:00
17 lines
460 B
TypeScript
17 lines
460 B
TypeScript
import { existsSync, readFileSync } from 'node:fs';
|
|
import process from 'node:process';
|
|
import { parse } from 'dotenv';
|
|
|
|
/**
|
|
* dotenv wrapper
|
|
* @param envPath 环境变量文件路径
|
|
*/
|
|
export default function loadDotEnv(envPath: string): void {
|
|
if (existsSync(envPath)) {
|
|
const parsed = parse(readFileSync(envPath, 'utf-8')) || {};
|
|
Object.keys(parsed).forEach((key) => {
|
|
process.env[key] = parsed[key];
|
|
});
|
|
}
|
|
}
|