occams-conf
A simple config module
Last updated 10 months ago by lxghtless .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install occams-conf 
SYNC missed versions from official npm registry.
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'
};

Windows Users

If an error resembling the following occurs, please check out the link below it.

PS C:\src\{projectfolder}> npm start

> file-sage@1.0.0 start C:\src\{projectfolder}
> node src/index.js

Error: ENOENT: no such file or directory, lstat 'C:\Users\{username}\AppData\Roaming\npm\node_modules'
    at Object.realpathSync (fs.js:1561:7)
    at Object.<anonymous> (C:\src\{projectfolder}\node_modules\is-installed-globally\index.js:8:29)
    at Module._compile (internal/modules/cjs/loader.js:1139:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
    at Module.load (internal/modules/cjs/loader.js:988:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1028:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at isGloballyInstalled (C:\src\{projectfolder}\node_modules\occams-conf\src\util.js:17:10)
    at getLocatorConfigPath (C:\src\{projectfolder}\node_modules\occams-conf\src\util.js:26:6) {
  errno: -4058,
  syscall: 'lstat',
  code: 'ENOENT',
  path: 'C:\\Users\\{username}\\AppData\\Roaming\\npm\\node_modules'
}

https://stackoverflow.com/questions/19874582/change-default-global-installation-directory-for-node-js-modules-in-windows

Current Tags

  • 3.0.0                                ...           latest (9 months ago)
  • 3.0.0-6                                ...           next (9 months ago)

11 Versions

  • 3.0.0                                ...           9 months ago
  • 3.0.0-6                                ...           9 months ago
  • 3.0.0-4                                ...           10 months ago
  • 3.0.0-3                                ...           10 months ago
  • 3.0.0-2                                ...           10 months ago
  • 3.0.0-1                                ...           10 months ago
  • 3.0.0-0                                ...           10 months ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |