Package Exports
- universal-dotenv
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (universal-dotenv) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Universal DotEnv

Universal DotEnv - A Robust Environment Configuration for Universal Applications.
This solution is heavily inspired by the approach chosen by Create React App and made available for general usage.
Features
- Supports loading
.envfiles with overriding between differentNODE_ENVsettings andENV_CONTEXTconfigurations. - Automatically adds a
APP_ROOTwhich points to the absolute root folder. - Also adds
APP_SOURCEwhich points to the source folder. - Serializes all
APP_prefixed environment variables for usage asraw,stringifiedorwebpack(forDefinePlugin) - Supports variable expansion between different settings.
- Allows local overrides using files which use a ".local" postfix.
All Strings
It is important to remember that all environment variables are always stored as strings. Even numbers and booleans. The casting to other types must therefore take place in the application code. See also: https://github.com/motdotla/dotenv/issues/51
Variables
NODE_ENV: Typically eitherproduction,developmentortestENV_CONTEXT: Often used for e.g.clientorserver. Can be also something totally custom e.g.docker,staging, etc.APP_ROOT: Points to the root folder of the application (absolute filesystem path)APP_SOURCE: Points to the source folder. Ifsrcexists this is being used. Otherwise the assumption is that it's identical to theAPP_ROOT.
File Priority
Files are being loaded in this order. Values which are already set are never overwritten. Command line environment settings e.g. via cross-env always win.
.env.${ENV_CONTEXT}.${NODE_ENV}.local.env.${ENV_CONTEXT}.${NODE_ENV}.env.${ENV_CONTEXT}.local.env.${ENV_CONTEXT}.env.${NODE_ENV}.local.env.${NODE_ENV}.env.local.env
Note: local files without NODE_ENV are not respected when running in NODE_ENV=test.
Basic Usage
All loading features are enabled by importing the core module itself:
import "universal-dotenv"After this you can access all environment settings you have defined in one of your .env files.
console.log(process.env.APP_MY_ENV)Serialization
The module offers access to all app specific environment settings which should be prefixed with APP_ e.g. APP_TITLE = "My App".
import { getEnvironment } from "universal-dotenv"
// This also loads all environment specific settings into `process.env`
const { raw, stringified, webpack } = getEnvironment()Return values:
- raw: Just a plain JS object containing all app settings
- stringified: Plain object but with JSON stringified values
- webpack: For usage with Webpacks Define Plugin
Webpack Usage:
import { getEnvironment } from "universal-dotenv"
const { webpack } = getEnvironment()
...
plugins.push(new webpack.DefinePlugin(webpack))License
Apache License Version 2.0, January 2004
Copyright
Copyright 2018-2019
Sebastian Software GmbH