envies
v3.0.0
Published
Teeny tiny .env loader
Readme
envies
Teeny tiny .env loader
Usage
import {env} from "envies";
console.log(env.USER);Details
It loads variables in ascending precedence from the following sources:
.default.envin the script directory.default.envin the working directory.envin the script directory.envin the working directory.env.localin the script directory.env.localin the working directory- The current environment variables
Notes
- Variables are loaded on-demand once when properties on
envare first accessed - The script directory is determined from
process.argv[1] - To change the default source filenames, set
ENVIES_SOURCES=.example.env,.envin the environment.
TypeScript
By default, env is typed as Record<string, string | undefined>. If you know specific variables will always be set, you can narrow their types via an ambient declaration (e.g. in types.d.ts):
declare module "envies" {
export const env: {
DATABASE_URL: string;
API_TOKEN: string;
};
}© silverwind, distributed under BSD licence
