# node-env-configuration

> A node.js module that helps with loading of hierarchical configuration from environment variables as suggested by twelve factor methodology

Latest version **1.0.3** (published 2017-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-env-configuration
pnpm add node-env-configuration
yarn add node-env-configuration
bun add node-env-configuration
```

## 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 | 1.0.3 |
| Published | 2017-01-24 |
| First published | 2014-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Ezequiel Cuñado |
| Maintainers | aimazio, ecunado |
| Keywords | node, config, 12factor, configuration, env, environment |

## Links

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

## Dependencies (1)

- [change-case](https://npm.io/package/change-case.md) ~1.0.6

## 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

- 1.0.3 (latest) — 2017-01-24
- 1.0.2 — 2016-04-17
- 1.0.1 — 2016-04-17
- 1.0.0 — 2016-04-16
- 0.0.7 — 2016-03-30
- 0.0.6 — 2015-08-11
- 0.0.5 — 2014-02-18
- 0.0.4 — 2014-02-18
- 0.0.3 — 2014-02-18
- 0.0.2 — 2014-02-17
- 0.0.1 — 2014-02-17
- 0.0.0 — 2014-02-17

## README

Description
===========
node-env-configuration is a node.js module that helps with loading configuration as suggested by twelve factor methodology www.12factor.net:

> **The twelve-factor app stores config in environment variables** (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.
…
In a twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars. They are never grouped together as “environments,” but instead are independently managed for each deploy. This is a model that scales up smoothly as the app naturally expands into more deploys over its lifetime.

# Quick Start
Suppose you have this json default configuration for your node application:

```javascript
var defaultConfiguration = {
  http_port: 8000,
  https_port: 8001,
  mongodb: {
    name: 'api', // Database name
    host: '127.0.0.1', // Database host
    user: '', // Database user
    password: '', // Database password
    port: 27017,
    options: {} // MongoDB options
  }
}
```

Then you want to override this configuration (or subset of it) for your production environment. You define the next environment variables :

```bash
API_APP_HTTP_PORT='80';
API_APP_HTTPS_PORT='443';
API_APP_MONGODB_NAME='api_db';
API_APP_MONGODB_HOST='api.example.com';
API_APP_MONGODB_USER='username';
API_APP_MONGODB_PASSWORD='secret password';
```

In your code your can override **defaultConfiguration** object with these environment variables:

```javascript
var nodeenvconfiguration = require('node-env-configuration');
var config = nodeenvconfiguration({
  defaults: defaultConfiguration,
  prefix: 'apiApp' // Read only env vars starting with API_APP prefix
});
```

# Notes

* Underscore character in environment variables (excluding prefix underscore) results in adding a new hierarchy level in result object:

```bash
API_APP_MONGODB_NAME = 'api_db'  # Matches obj.mongodb.name property
API_APP_MONGODB_URL_HOST = 'api.example.com'  # Matches obj.mongodb.url.host propery
```

# Configuration parameters
Name  | Default Value | Description
------|---------------|-------------
`prefix` | '' | **Pascal case** prefix. Restrict variables to read from environment to those starting with this prefix in **snake case**
`arraySeparator` | null | This character, if specified, is used as an array separator. So if a variable contains this character, the variable is parsed as an array of values
`defaults` | {} | Default object values

# Running Tests

```bash
$ npm test
```

# License

[MIT](https://github.com/whynotsoluciones/node-env-configuration/blob/master/LICENSE "MIT")

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