2.0.0 • Published 5 years ago

multi-env v2.0.0

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

multi-env

npm version Build Status codecov Greenkeeper badge

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

Multi-env is built on dotenv and follows the same rules.

Installation

npm install --save multi-env

Configuration

Add configuration for multi-env to your package.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

// 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 to preload multi-env. By doing this, you do not need to require and execute multi-env in your application code.

{
  "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"
      ]
    }
  }
}
// src/index.js
console.info(process.env.MY_VARIABLE_FROM_DOTENV);

...
2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.0.3

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago