0.0.3 • Published 4 years ago
@micra/dot-env v0.0.3
About
Creates a environment instance that gives access to .env*
file definitions and the process.env.*
. Under the hood, this package wraps Dotenv-flow. Checkout their docs for more info on how to declare your .env*
files!
Installation
yarn add @micra/dot-env
Usage
Standalone
import { DotEnv } from '@micra/dot-env';
const env = new DotEnv();
env.get('NODE_ENV', 'production');
@micra/application
// In your src/app/environment/index.ts
import app from '@micra/application';
import { DotEnv } from '@micra/dot-env';
app.registerEnv(DotEnv);
// Somewhere else in your application:
env('NODE_ENV', 'production');
API
env.get<K extends keyof NodeJS.ProcessEnv>(key: K, fallback?: NodeJS.ProcessEnv[K]): NodeJS.ProcessEnv[K] | undefined
:
Returns the value of a given environment variable. A fallback can be passed as a second arguments in case the given variable is not defined.
env.has(key: keyof NodeJS.ProcessEnv): boolean
:
Checks if a given variable is defined.