# loadenv

> Loads environment variables from project's `./configs/` directory based on NODE_ENV.

Latest version **2.2.0** (published 2016-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install loadenv
pnpm add loadenv
yarn add loadenv
bun add loadenv
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2016-04-15 |
| First published | 2015-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Ryan Sandor Richards |
| Maintainers | rsandor, runnabear |

## Links

- npm: https://www.npmjs.com/package/loadenv
- Repository: https://github.com/Runnable/loadenv
- Homepage: https://github.com/Runnable/loadenv#readme
- Issues: https://github.com/Runnable/loadenv/issues
- npm.io page: https://npm.io/package/loadenv

## Dependencies (5)

- [101](https://npm.io/package/101.md) ^0.14.1
- [eson](https://npm.io/package/eson.md) ^0.5.0
- [clone](https://npm.io/package/clone.md) ^1.0.2
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [dotenv](https://npm.io/package/dotenv.md) ^1.1.0

## Recent versions

- 2.2.0 (latest) — 2016-04-15
- 2.1.0 — 2015-10-21
- 2.0.2 — 2015-10-21
- 2.0.1 — 2015-10-15
- 2.0.0 — 2015-10-13
- 1.1.0 — 2015-05-14
- 1.0.3 — 2015-04-06
- 1.0.2 — 2015-04-05
- 1.0.1 — 2015-04-05
- 1.0.0 — 2015-04-05

## README

# loadenv

![Build Status](https://travis-ci.org/Runnable/loadenv.svg?branch=master)
![Dependency Status](https://david-dm.org/Runnable/loadenv.svg)
![devDependency Status](https://david-dm.org/Runnable/loadenv/dev-status.svg)

[![NPM](https://nodei.co/npm/loadenv.png?compact=true)](https://nodei.co/npm/loadenv)

Utility for loading environment variables from a project's `configs/` directory.

## How it works

The module first finds your application's root directory and then attempts to
load environment variables found in the `configs/.env` file. Then, if a specific
`NODE_ENV` exists in the environment at run time it additionally loads variables
from the `configs/.env.${NODE_ENV}` file. *Note*: This module will not work if
installed globally [`npm install loadenv -g`].

### An Example

Suppose you have your project setup with the following configs:

```
configs/.env
  A=1
  B=2
configs/.env.test
  B=3
  C=4
```

If you launched your application without a `NODE_ENV` variable set, and called
into the module like so:

```js
require('loadenv')();
```

then the resulting `process.env` would now contain the following:

```
process.env.A === 1
process.env.B === 2
```

If instead, you launched your application with `NODE_ENV=test` then the
`process.env` would include the following:

```
process.env.A === 1
process.env.B === 3
process.env.C === 4
```

### Logging the Resulting Environment

The module uses debug to log the resulting environment after it has been loaded
from the `configs/` files. By default it uses `debug('loadenv')` but you can
override this by calling into the module with a custom name, like so:

```js
// Pass an options object:
require('loadenv')({
  debugName: 'myapp:env'
});

// Or just use a string if you only need the debug name
require('loadenv')('myapp:env') ;
```

If you were to do so then the module would use `debug('myapp:env')` to log the
resulting output.

### Only Loads Environment Once

No matter how many times you include the module, the environment is only loaded
once. So feel free to sprinkle loads wherever they might be needed to make your
code as modular as possible.

## Developing

If you want to contribute, make sure that all tests pass with 100% coverage
before submitting a pull request. Here's how to run the tests:

```
npm test
```


## LICENSE

MIT

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