UNPKG

@adonisjs/env

Version:

Environment variable manager for Node.js

44 lines (43 loc) 1.29 kB
/** * Read the contents of one or more dot-env files. Following is how the files * are read. * * - Load file from the "ENV_PATH" environment file. * (Raise error if file is missing) * * - If "ENV_PATH" is not defined, then find ".env" file in the app root. * (Ignore if file is missing) * * - Find ".env.[NODE_ENV]" file in the app root. * (Ignore if file is missing) * * ```ts * const loader = new EnvLoader(new URL('./', import.meta.url)) * * const { envContents, currentEnvContents } = await loader.load() * * // envContents: Contents of .env or file specified via ENV_PATH * // currentEnvContents: Contents of .env.[NODE_ENV] file * ``` */ export declare class EnvLoader { #private; /** * Creates a new EnvLoader instance * * @param appRoot - The application root directory as string or URL * @param loadExampleFile - Whether to load .env.example file */ constructor(appRoot: string | URL, loadExampleFile?: boolean); /** * Load contents of the main dot-env file and the current * environment dot-env file * * @returns Promise resolving to array of loaded environment files */ load(): Promise<{ contents: string; path: string; fileExists: boolean; }[]>; }