# lazy-universal-dotenv

> Robust Environment Configuration for Universal Applications.

Latest version **4.0.0** (published 2023-01-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install lazy-universal-dotenv
pnpm add lazy-universal-dotenv
yarn add lazy-universal-dotenv
bun add lazy-universal-dotenv
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2023-01-30 |
| First published | 2018-10-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14.0.0 |
| Dependencies | 3 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Storybook Team |
| Maintainers | ndelangen, hypnosphi, igor-dv |
| Keywords | dotenv, env, universal |

## Links

- npm: https://www.npmjs.com/package/lazy-universal-dotenv
- Repository: https://github.com/storybooks/lazy-universal-dotenv
- Homepage: https://github.com/storybooks/lazy-universal-dotenv#readme
- Issues: https://github.com/storybooks/lazy-universal-dotenv/issues
- npm.io page: https://npm.io/package/lazy-universal-dotenv

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^16.0.0
- [app-root-dir](https://npm.io/package/app-root-dir.md) ^1.0.2
- [dotenv-expand](https://npm.io/package/dotenv-expand.md) ^10.0.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2023-01-30
- 3.0.1 — 2019-07-29
- 3.0.0 — 2019-06-19
- 2.0.0 — 2018-10-14
- 1.9.1 — 2018-10-14

## README

# Lazy Universal DotEnv

[npm]: https://www.npmjs.com/package/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](https://www.npmjs.com/package/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

```js
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:
```js
import { getEnvironment } from "lazy-dotenv-universal";

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

Code being bundled by webpack:
```js
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](https://webpack.js.org/plugins/define-plugin/)


## License

[Apache License Version 2.0, January 2004](license)

## Copyright

Copyright 2018<br/>[Sebastian Software GmbH](http://www.sebastian-software.de)

---
_Source: https://npm.io/package/lazy-universal-dotenv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
