Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weisjohn/scopenv
environment variables with any number of prefixes
https://github.com/weisjohn/scopenv
Last synced: about 1 month ago
JSON representation
environment variables with any number of prefixes
- Host: GitHub
- URL: https://github.com/weisjohn/scopenv
- Owner: weisjohn
- License: mit
- Created: 2013-11-21T18:31:44.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-02-13T07:06:16.000Z (almost 10 years ago)
- Last Synced: 2024-11-12T23:33:06.944Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 129 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
scopenv
==========### environment variables with optional, variadic prefixes
scopenv allows you to pull in configuration values from your environment variables while specifying optional prefixes that should be honored. This is helpful when colocating a number of instances of generic apps that use similar variable names but need different values.
## usage
Given an environment (e.g. `~/.bashrc` or `~/.bash_profile`) like:
```bash
export HOST='localhost'
export DB_HOST='123.45.67.89'
export DB_PASS='password123'
export MYAPPNAME_DB_HOST="127.0.0.1"
```You could retrieve your application's configuration by specifying the environment variables to retrieve and a number of prefixes to attempt to use.
```javascript
var scopenv = require('scopenv');
console.log(scopenv(['host', 'pass'], 'db', 'myappname'))
```Output
```javascript
{ host: '127.0.0.1', pass: 'password123' }
```This is especially helpful in development if you want to simply define a set of variables, but in staging or production, you want to configure each application separately.
If you didn't specify 'myappname', you'd get:
```javascript
var scopenv = require('scopenv');
console.log(scopenv(['host', 'pass'], 'db'))
```Output
```javascript
{ host: '123.45.67.89', pass: 'password123' }
```NOTE: scopenv can be invoked with any number of prefixes.