make-confdeprecated

Merge environment variables into config object

Usage no npm install needed!

<script type="module">
  import makeConf from 'https://cdn.skypack.dev/make-conf';
</script>

README

React Native AutoLink

NPM Version Build Status Dependency Status Dev Dependency Status

Config builder for Node projects. Merges environment variables with default config object(s) to produce simple config object and allows all config options to be overridable via environment variables.

Installation

npm install make-conf --save

Behavior

All keys are converted to camel-case and nested appropriately based on the following rules:

  • Single underscore -> camel-case (e.g. NODE_ENV becomes nodeEnv)
  • Double underscore -> nested object (e.g. APP__NAME becomes app.name)

After converting keys, values are merged:

  • Objects are merged recursively
  • All other values (e.g. arrays, strings) are replaced

Usage

Pass in any config sources to get merged config result.

const makeConf = require('make-conf');

// Using a default object
const conf = makeConf({ nodeEnv: 'development', appName: 'awesome-app' }, ...configObjects)

// Using folder of YAML files
const conf = makeConf({ someKey: 'default' }, ...fs.readdirSync('./config').map(file => yaml.load(fs.readFileSync(path.join('./config', file), 'utf8'))));

// Example
// Environment variables: NODE_ENV=production APP__VERSION=2.0.0
const conf = makeConf({ nodeEnv, 'development', app: { name: 'Test', version: '1.0.0' }}, { app: { name: 'makeConf' }});
// { nodeEnv: 'production', app: { name: 'makeConf', version: '2.0.0' }}