Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.