dotenv-local
Version:
A utility library for loading local environment variables with prioritized file loading in Node.js and Vite projects. Extends dotenv functionality for better environment management in various modes like development, production, and testing.
45 lines (43 loc) • 1.5 kB
TypeScript
/**
* Options for loading environment variables.
*/
type LoadEnvOpts = {
/**
* Directory where the environment variable files are located.
* If not specified, the current working directory will be used.
* @default process.cwd()
*/
envDir?: string;
/**
* The mode for the environment. Common modes are "development", "production",
* "testing", "staging". If not provided, it can be any string value.
* @default process.env.NODE_ENV || "production"
*/
mode?: "development" | "production" | "testing" | "staging" | string;
/**
* Prefix to filter environment variables. Can be a single string or an array of strings.
* If not specified, no prefix filtering is applied.
* @default "APP_"
*/
envPrefix?: string | string[];
/**
* Initial set of environment variables to be loaded.
* If not provided, no initial variables will be set.
* @default {}
*/
envInitial?: Record<string, string>;
/**
* If true, removes the environment variable prefix from the variable names.
* If false or not provided, the prefix will be preserved.
* @default false
*/
removeEnvPrefix?: boolean;
/**
* The encoding used for reading environment files. Typically "utf-8".
* If not specified, defaults to "utf-8".
* @default "utf-8"
*/
encoding?: string;
};
declare const loadEnv: (opts?: LoadEnvOpts) => Record<string, string>;
export { LoadEnvOpts, loadEnv };