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.
Given an environment (e.g.
export HOST='localhost'export DB_HOST='220.127.116.11'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.
var scopenv = require'scopenv';console.logscopenv'host' 'pass' 'db' 'myappname'
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:
var scopenv = require'scopenv';console.logscopenv'host' 'pass' 'db'
host: '18.104.22.168' pass: 'password123'
NOTE: scopenv can be invoked with any number of prefixes.