UNPKG

@modern-js/server-core

Version:

A Progressive React Framework for modern web development.

23 lines (22 loc) 610 B
import path from "path"; import { fs, dotenv, dotenvExpand } from "@modern-js/utils"; async function loadServerEnv(options) { const { pwd } = options; const serverEnv = process.env.MODERN_ENV; const defaultEnvPath = path.resolve(pwd, `.env`); const serverEnvPath = path.resolve(pwd, `.env.${serverEnv}`); for (const envPath of [ serverEnvPath, defaultEnvPath ]) { if (await fs.pathExists(envPath) && !(await fs.stat(envPath)).isDirectory()) { const envConfig = dotenv.config({ path: envPath }); dotenvExpand(envConfig); } } } export { loadServerEnv };