Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jlegrone/multi-env
Merges and loads environment variables from multiple .env files for nodejs projects.
https://github.com/jlegrone/multi-env
Last synced: 16 days ago
JSON representation
Merges and loads environment variables from multiple .env files for nodejs projects.
- Host: GitHub
- URL: https://github.com/jlegrone/multi-env
- Owner: jlegrone
- License: mit
- Created: 2017-11-14T19:26:12.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-26T21:31:07.000Z (over 4 years ago)
- Last Synced: 2024-11-20T03:39:29.026Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 6.1 MB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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);...
```