# multi-env

> Merges and loads environment variables from multiple .env files for nodejs projects.

Latest version **2.0.0** (published 2019-05-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install multi-env
pnpm add multi-env
yarn add multi-env
bun add multi-env
```

## 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.0.0 |
| Published | 2019-05-04 |
| First published | 2017-11-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8 |
| Dependencies | 3 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jacob LeGrone |
| Maintainers | jlegrone |

## Links

- npm: https://www.npmjs.com/package/multi-env
- Repository: https://github.com/jlegrone/multi-env
- Homepage: https://github.com/jlegrone/multi-env#readme
- Issues: https://github.com/jlegrone/multi-env/issues
- npm.io page: https://npm.io/package/multi-env

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^8.0.0
- [pkg-up](https://npm.io/package/pkg-up.md) ^2.0.0
- [dotenv-expand](https://npm.io/package/dotenv-expand.md) 5.1.0

## Recent versions

- 2.0.0 (latest) — 2019-05-04
- 1.1.2 — 2019-03-18
- 1.1.1 — 2019-03-13
- 1.1.0 — 2019-03-13
- 1.0.0 — 2019-02-03
- 0.0.3 — 2017-12-13
- 0.0.1 — 2017-11-15
- 0.0.0 — 2017-11-15

## README

# multi-env

[![npm version](https://badge.fury.io/js/multi-env.svg)](https://badge.fury.io/js/multi-env)
[![Build Status](https://travis-ci.org/jlegrone/multi-env.svg?branch=master)](https://travis-ci.org/jlegrone/multi-env)
[![codecov](https://codecov.io/gh/jlegrone/multi-env/branch/master/graph/badge.svg)](https://codecov.io/gh/jlegrone/multi-env) [![Greenkeeper badge](https://badges.greenkeeper.io/jlegrone/multi-env.svg)](https://greenkeeper.io/)

Multi-env merges and loads environment variables from multiple `.env` files for nodejs projects.

Multi-env is built on [dotenv](https://github.com/motdotla/dotenv) and follows the same [rules](https://github.com/motdotla/dotenv#rules).

## Installation

```bash
npm install --save multi-env
```

## Configuration

Add configuration for multi-env to your `package.json`:

```json
{
  "name": "my-package",
  "version": "0.1.0",
  "scripts": {
    "start": "node ./src/index.js"
  },
  "config": {
    "multi-env": {
      "files": [
        "local.env",
        "shared.env"
      ]
    }
  }
}
```

`files` should be an array of `.env` file paths (relative to `package.json`).

When the same variable is assigned in multiple files, the earliest file listed in your configuration will take precedence. Environment variables that have already been set will never be modified.

## Usage

### In Application Code

```javascript
// src/index.js
require('multi-env')();

console.info(process.env.MY_VARIABLE_FROM_DOTENV);

...
```

### Preload

You can use the node --require (-r) [command line option](https://nodejs.org/api/cli.html#cli_r_require_module) to preload multi-env. By doing this, you do not need to require and execute multi-env in your application code.

```json
{
  "name": "my-package",
  "version": "0.1.0",
  "scripts": {
    "start": "node -r multi-env/config ./src/index.js"
  },
  "config": {
    "multi-env": {
      "files": [
        "local.env",
        "shared.env"
      ]
    }
  }
}
```

```javascript
// src/index.js
console.info(process.env.MY_VARIABLE_FROM_DOTENV);

...
```

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