@creativefeather/config

0.5.0 • Public • Published

Config

My little project: a config module which aims to focus on making the important parts of environment, and app, configuration [secure,] simple, and easy to use.

[STATUS] Basic basic features A-OK!

Quick Start

Install

 $ npm install @creativefeather/config --save

After installing create the env.js[on] config file in the {project_root}/config directory. Add properties and enjoy!

// env.json || env.js
{
  "development": {}
}

Options

path

By default the module will look in the project root directory for a folder called config. The config path used to search for configuration files can be changed in various ways like so:

// package.json
{
  "name": "my-module",
  "config": {
    "config path": "path/to/config/dir"
  }
}

// In Code (via module)
const config = require('@creativefeather/config');
config({
  use: true,  // option to set module aquired config
  path: "path/to/config/dir"
});

// In Code (before requiring the module)
process.env.CONFIG_OPTION_PATH = 'path/to/config/dir';

// Env Variable
$ CONFIG_OPTION_PATH=path/to/config/dir

env

If no environment is specified, the default will be "development"--however, if there is an environment specified in env.json that begins with 'prod', an error will be thrown instead. If you want to use a different configuration, some ways of specifying it are more practial than others for a typical project. . .

// Environment Variable
$ NODE_ENV=production
// OR
$ CONFIG_OPTION_ENV=production

// In Code (via module)
const config = require('@creativefeather/config');
config({
  use: true,  // option to set module aquired config
  env: "production"
});

// In Code (before requiring the module)
process.env.NODE_ENV = 'production';
// OR
process.env.CONFIG_OPTION_ENV = 'production';

// Env Variable
$ CONFIG_OPTION_ENV=production

Config Files

index.js[on] is where to put default values and values that aren't specific to a particular deployment or sensitive in anyway. It is not required to have this file; but, you should be aware of it for when the need arises.

env.js[on] is where sensitive info and environment specific settings will go. That way, you don't have to commit any of it to the public.

// *** Example Usage ***

// env.js
{
  "all": {
    "db": {
      "username": "cmonster",
      "password": "chocolatechip",
      "host": "localhost",
      "port": 3000
    }
  },

  "development": {
    "logger": new Logger({
      "level": "info"
    }),
    "db": {
      "name": "coolapp"
      "name+TEST": "test"    
    }
  }
}

// index.json
{
  "logger": null
}

If you have more than one configuration in env.js[on], you can put shared values in "all". Properties in the active configuration will override the values in 'all'. Finally, 'env' will be merged with 'index' where 'env' values take priority.

Package Sidebar

Install

npm i @creativefeather/config

Weekly Downloads

6

Version

0.5.0

License

MIT

Unpacked Size

74.4 kB

Total Files

34

Last publish

Collaborators

  • creativefeather