@creativefeather/config
darn small configuration framework for node apps
Last updated 2 years ago by creativefeather .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @creativefeather/config 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.5.0                                ...           latest (2 years ago)

19 Versions

  • 0.5.0                                ...           2 years ago
  • 0.4.6                                ...           2 years ago
  • 0.4.5                                ...           2 years ago
  • 0.4.4                                ...           2 years ago
  • 0.4.3                                ...           2 years ago
  • 0.4.2                                ...           2 years ago
  • 0.4.1                                ...           2 years ago
  • 0.4.0                                ...           2 years ago
  • 0.3.2                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.6                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.4                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 30
Last Day 0
Last Week 20
Last Month 11
Dependencies (3)
Dev Dependencies (3)

Copyright 2014 - 2016 © taobao.org |