Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

occams-conf

3.0.0-6 • Public • Published
occams-conf

A simple config module

npm version CircleCI codecov XO code style

Why Occam's Config?

  • Encourages Build Once Run Anywhere Node.js App Containers
  • No opinion of config file name or location
  • Load additional config files to merge properties
  • Load configs from https endpoints

previous versions

first things's first...

$ npm i occams-conf

Usage

load main config via occams settings

const config = require('occams-conf');
 
console.log(config.yourProp);

load another config merged with main

const config = require('occams-conf');
config.loadConfig({
    name: 'other-config.js',
    path: 'src'
});
 
console.log(config.yourProp);
console.log(config.otherProp);

load config from https url with loaderConfig

// example loaderConfig:
// {
//     "path": "https://raw.githubusercontent.com/lxghtless/occams-conf/v2.0.1/config.js"
// }
const config = require('occams-conf');
 
(async () => {
    await config.init();
    console.log(config.resourceUrl);
});

load config from https url with loadConfig method

const config = require('occams-conf');
 
(async () => {
    await config.loadConfig({
        path: 'https://raw.githubusercontent.com/lxghtless/occams-conf/v2.0.1/config.js'
    });
    console.log(config.resourceUrl);
});

occams-conf settings file (aka locatorConfig)

  • name (config file name) [String]
  • path (config path) [String]

Any of these will work and will resolve the first one found in this order.

occams.conf.json

{
    "name": "config.js",
    "path": "src"
}

occams.conf.js

const conf = {
    name: 'config.js',
    path: 'src'
};
 
module.exports = conf;

package.json

{
    "occams-conf": {
        "name": "config.js",
        "path": "src"
    }
}

default

  • name: config.js
  • path: $HOME directory if globally installed || cwd

Example config.js

module.exports = {
    port: process.env.TEST_PORT || 8011,
    name: process.env.TEST_NAME || 'starlord',
    resourceUrl: process.env.TEST_URL || 'https://reqres.in/api/mixtapes'
};

Keywords

Install

npm i [email protected]

Version

3.0.0-6

License

ISC

Unpacked Size

17.4 kB

Total Files

10

Last publish

Collaborators

  • avatar