lazy-universal-dotenv
Robust Environment Configuration for Universal Applications.
Last updated 2 years ago by ndelangen .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install lazy-universal-dotenv 
SYNC missed versions from official npm registry.

Lazy Universal DotEnv

Lazy Universal DotEnv - A Robust Environment Configuration for Universal Applications.

Features

  • Supports loading .env files with overriding between different NODE_ENV settings and BUILD_TARGET configurations.
  • 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 either production, development or test
  • BUILD_TARGET: Either client or server

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.${BUILD_TARGET}.${NODE_ENV}.local
  • .env.${BUILD_TARGET}.${NODE_ENV}
  • .env.${BUILD_TARGET}.local
  • .env.${BUILD_TARGET}
  • .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

import { getEnvironment } from "lazy-dotenv-universal";

const environment = getEnvironment({ nodeEnv, buildTarget });

const { raw, stringified, webpack } = environment;

After this you can access all environment settings you have defined in one of your .env files.

A .env file:

MY_END=awesome

Webpack config:

import { getEnvironment } from "lazy-dotenv-universal";

export default {
  // ... 
  plugins: [
    new webpack.DefinePlugin(getEnvironment().webpack),
  ],
  // ...
}

Code being bundled by webpack:

console.log(process.env.MY_ENV); // -> "awesome"

Serialization

  • 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

License

Apache License Version 2.0, January 2004

Copyright

Copyright 2018
Sebastian Software GmbH

Current Tags

  • 4.0.0                                ...           latest (2 years ago)

5 Versions

  • 4.0.0                                ...           2 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           6 years ago
  • 1.9.1                                ...           6 years ago
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE