https://github.com/iansu/config4
Similar to config3 but with some changes for Lottery.com
https://github.com/iansu/config4
Last synced: about 2 months ago
JSON representation
Similar to config3 but with some changes for Lottery.com
- Host: GitHub
- URL: https://github.com/iansu/config4
- Owner: iansu
- Created: 2018-10-30T21:26:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-17T16:38:05.000Z (over 6 years ago)
- Last Synced: 2025-01-26T06:44:53.982Z (4 months ago)
- Language: JavaScript
- Size: 124 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Config4
This is a configuration library based on config3 but adapted to the pattern most commonly used on projects at Lottery.com.
**Significant Changes**
- Loads from 4 places: config.default.js, config.environent.js, config.local.js and environment
- Automatically parses booleans in environment vars that look like booleans `VARNAME=true`
- Automatically parses numbers in environment vars that look like numbers eg. `VARNAME=2`
- Parses double underscore `__` in environment vars as nested objects## How To Use
Add to your package.json
` "config4": "git+https://github.com/autolotto/config4.git#0.1.0", `
Import
` const config = require('config4'); `
Use
` const myVar = config.SOME_CONSTANT; `
## What To Commit
Because you can have environment specific configuration files AND set environment variables, a good convention is:
1. Put common configuration in `config.default.js`
2. Put non-secret environment configuration in `config.production.js`
3. Put secret environment configuration (like credentials) in environment variable on HerokuThis way, we:
- Are not committing any credentials or passwords to git
- Have a manageable number of environment variables
- Can easily add settings like feature flags to files when we write code## Environment Vars Nested Objects
Environment variables like this:
```
MONKEY__SEE__DO=banana
```become
```
MONKEY: {
SEE: {
DO: "banana"
}
}
```## Load Order
Loads configuration in the following order:
`config.default.js` - Loaded first and sets up any universal defaults.
`config.{environment}.js` - Loaded second and does environment specific configs.
`config.local.js` - Override or add to anything that you set in default file.
`environment vars` - Environment vars override everything.
## Attribution for Past Work
- Inspired by config3 which was used at lottery.com in the past
- Based on some code from configery, a deprecated lottery.com library