1.3.3 • Published 4 years ago

cnm-config v1.3.3

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

CNM-config

This repository is there to load configuration variables from your environment and that check for required variables or sets default values etc. It exports a function to which you can give an array of all the variables needed

Usage

const load = require('cnm-config');

const config = [{
  name: 'PORT',
  'default': 8080,
  type: 'int',
}, {
  as: 'env',
  name: 'NODE_ENV',
  'default': 'development',
}, {
  as: 'connection',
  name: 'DB_CONNECTION',
  required: true,
}, {
  as: 'prodSecret',
  name: 'PROD_SECRET',
  required: ({ env }) => env === 'production',
}]

const { connection, env, prodSecret, PORT } = load(config);

// Do things with your config variables

Detail

A variable description can have several options :

  • name (string, required) : the name of the environment variable
  • as (string) : the name the variable will have in the resulting object
  • required (boolean | function) : whether the variable is required or not, you can give it a function taking in argument the values of the resulting object and returning a boolean
  • default (any) : a default value if the variable is not defined and not required
  • type ('bool' | 'boolean' | 'int' | 'number' | 'integer' | 'list') : the type of the variable
  • description (string) : a description of what the variable do to be used as documentation
1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.2.5

4 years ago

1.3.0

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago