configa

app configuration management for node.js

Usage no npm install needed!

<script type="module">
  import configa from 'https://cdn.skypack.dev/configa';
</script>

README

configa

app configuration management for node.js

This is a really simple module. It basically allows you to have a mix of configuration/arguments in the form of CLI arguments, ENV vars, and defaults. The important thing is the priority in case the values are set in multiple ways. The values are returned using the following priority:

  1. CLI Arguments (argv)
  2. ENV Variable (process.env)
  3. Default value

Usage

Installation:

npm install configa

Setup:

var config = require('configa')();

config
  .option({
    name: 'port',
    env: 'PORT',
    alias: 'p', // a cli alias like -p
    type: Number,
    default: 3000
  })
  .option({
    name: 'foo',
    env: 'FOO',
    alias: 'f',
    type: String,
    default: 'bar'
  })
  .option({
    name: 'bar',
    env: 'BAR',
    type: Boolean,
    default: false
  });

And the getter:

var val = config.get('port');

The store() method caches the calculated values for performance:

config
  .option({
    name: 'port',
    env: 'PORT',
    alias: 'p', // a cli alias like -p
    default: 3000
  })
  .store();