npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kea-config

v0.2.3

Published

Configuration manager support merging configurations base on Node.js environment, references to other keys and using templates with objects for complex string values

Downloads

74

Readme

Kea-logo

NPM version

kea-config

Configuration manager for Node.js applications with perfect performance and without dependencies. Main feature of this configuration manager is merging configuration files depending on Node.js environment, support references to other keys and using templates with objects for complex string values.


    configManager.setup('./config');
    // For process.env.NODE_ENV === 'development';
    configManager.get('web.port'); // 4343
    // For process.env.NODE_ENV === 'production';
    configManager.get('web.port'); // 7474

    // If you don't want to apply changes connected to environment
    // just use init method
    configManager.init('./config/main.conf.js');
    configManager.get('web.port'); // 3005

    var config = {}

    config.web = {
        port: 3005,
        sessionKey: '6ketaq3cgo315rk9',
        paging: {
            defaultPageSize: 25,
            numberVisiblePages: 10
        },
        mongoDb: {
            username: 'dbUser',
            password: 'strongPassword',
            host: 'localhost',
            port: 27101,
            db: 'database'
        },
        propertyReference: {
            $ref: 'web.paging.defaultPageSize'
        },
        templateReference: {
            $ref: 'web.mongoDb',
            $tmpl: 'mongodb://{username}:{password}@{host}:{port}/{db}'
        }
    };

    module.exports = config;

    var config = {}

    config.web = {
        port: 4343
    };

    module.exports = config;

    var config = {}

    config.web = {
        port: 7474
    };

    module.exports = config;

Install with npm:

npm install kea-config --save

In your code require the package:

var configManager = require('kea-config');

Setup configuration data

configManager.setup('./config');

This command will initialize configManager by main.conf.js in and then merge development.conf.js (if NODE_ENV === development)

Read (get) and write (set) config data:


    var sessionSecret = configManager.get('web.sessionKey');
    configManager.set('web.paging.defaultPageSize', 15);
    // also
    webConfig = configManager.get('web.paging');
    /*
        {
            defaultPageSize: 15,
            numberVisiblePages: 10
        }
    */

    // Usage references

    configManager.get('web.propertyReference'); // 25

    // Usage templates

    configManager.get('web.templateReference'); // 'mongodb://dbUser:strongPassword@localhost:27101/database' - string
  • npm test or gulp mocha - run tests
  • gulp cover - check tests coverage
  • gulp benchmark - rum performance test
  • gulp readme - prepare README.md from documentation folder
Statements ................................... 100% ( 123/123 )
Branches ..................................... 96.67% ( 58/60 )
Functions .................................... 100% ( 20/20 )
Lines ........................................ 100% ( 123/123 )
Get simple key ............................... 5,799,240 ops/sec +0.47%
Get deep key ................................. 5,488,370 ops/sec +0.31%
Get key with reference ....................... 1,508,501 ops/sec +0.23%
Get key with reference and template .......... 106,877 ops/sec +0.27%
Get key with deep references ................. 274,983 ops/sec +0.80%
Get key with deep references and template .... 108,919 ops/sec +0.25%
Set simple key ............................... 3,446,469 ops/sec +0.26%
Set deep key ................................. 3,135,072 ops/sec +1.82%
  • support .yml, .yaml, .coffee, .cson, .properties, .json, .json5, .hjson
  • adapters for different storages like (filesystem, DB, localstorage / sessionstorage, web api and etc.)
  • save current state of config
  • delete key

MIT

Image from thetartankiwi

kea-config.setup(dirPath)

Full init config based on environment variable NODE_ENV. If NODE_ENV not available use development as default. This method looking for two files main (name started from 'main' word) and file with name started from environment (like development, staging, production)

Kind: static method of kea-config

| Param | Type | Description | | --- | --- | --- | | dirPath | string | object | path to folder with configuration files, from project root |

kea-config.init(path)

ConfigManager initialization by data in file. Not save previous configuration.

Kind: static method of kea-config

| Param | Type | Description | | --- | --- | --- | | path | string | path to CommonJs module with configuration, from project root |

kea-config.update(path)

Update exist configuration. Merge new config to exist.

Kind: static method of kea-config

| Param | Type | Description | | --- | --- | --- | | path | string | path to CommonJs module with configuration, from project root |

kea-config.setData(data, isMerge)

Set / merge data in configuration manager

Kind: static method of kea-config

| Param | Type | Description | | --- | --- | --- | | data | object | configuration data | | isMerge | boolean | should manager merge data to exist configuration |

kea-config.getData()

Get whole configuration as an object

Kind: static method of kea-config

kea-config.get(key) ⇒ *

Get 'value' of 'key'.

Kind: static method of kea-config
Returns: * - value - value of key. Can be primitive or javascript object. Objects not connected to original configuration. If value contain reference ({$ref: 'some.reference.to.other.key'}), then return reference value, if value contain reference with template({ $ref: 'some.reference', $tmpl: '{some}:{template}.{string}' }) and reference point to object then return string with populated placeholder in template (look example on top of page).

| Param | Type | Description | | --- | --- | --- | | key | string | key in configuration. Like 'simpleKey' or 'section.subsection.complex.key'. See config-managet-test.js |

Example

Kind: static method of kea-config

| Param | Type | Description | | --- | --- | --- | | key | string | key in configuration. Like 'simpleKey' or 'section.subsection.complex.key'. See config-managet-test.js | | value | * | |

kea-config.has(key) ⇒ boolean

Check availability of key in configuration

Kind: static method of kea-config

| Param | | --- | | key |