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

confim

v2.0.0

Published

A smart configuration management tool

Downloads

9

Readme

Confim

A smart configuration management module

What does it do

This modules allows you to easily manage the configuration of small and big applications with environment variable and multi environment support

Install

NPM has you covered: npm i -S confim

Example

Example configuration file config.js

module.exports = {
    modules: {
        database: {
            default: {
                port: 1234
            },
            development: {
                host: 'database.dev.internal'
            },
            integration: {
                host: 'database.int.internal'
            },
            production: {
                host: 'database.prod.internal'
            }
        }
    },
    shared: {
        default: {
             loglevel: "info"
            },
            "development": {
              "loglevel": "debug"
            },
            "integration": {
              "loglevel": "error"
            },
            "production": {
              "loglevel": "warn"
            }
    },
    aliases: {
        'primary-server': "web-server-two"
    }
};

  "shared": {
    "*": {
      "loglevel": "info"
    },
    "development": {
      "loglevel": "debug"
    },
    "integration": {
      "loglevel": "error"
    },
    "production": {
      "loglevel": "warn"
    }
  },
  "modules": {
    "web-server-one": {
      "*": {
        "port": 3000,
        "host": "127.0.0.1"
      },
      "development": {
        "host": "0.0.0.0"
      }
    },
    "web-server-two": {
      "*": {
        "port": 4000,
        "host": "127.0.0.1"
      },
      "development": {
        "host": "0.0.0.0"
      }
    },
    "database": {
      "*": {
        "loglevel": "info",
        "username": "foo",
        "database": "bar",
        "password": "___CONFIM___REQUIRED___"
      },
      "development": {
        "host": "localhost",
        "password": "weakPassFoLocal"
      },
      "integration": {
        "host": "db.integration.example.org"
      },
      "production": {
        "host": "db.production.example.org"
      }
    }
  }
}
What are we defining
  • three modules:
    • web-server-one
    • web-server-two (notice we defined loglevelwhich overrides the shared property)
    • database
  • a shared loglevel property accessible to every module
  • an alias for web-server-two named primary-server
How it works

The default key in the modules and in the shared key is the default to use for any environment where the key is not defined. We use a special __CONFIM_REQUIRED__ key in database module. This makes sure that the value is present as environment variable or in a specific environment. In the example password is defined in development unlike integration and production. When you do not provide it via env DATABASE_password=bla and the environment is not development the app will fail as soon as the configuration is read from file

Get the data

Create a ìndex.js file in the same directory or a child directory of the config.js file and paste the following content.

// file: index.js

var Confim = require('confim').default; // import confim using es5
//import Confim from 'confim'; // import confim using es6

// Get database config merged with shared and of current environment
var dbConf = Confim('database').conf;
console.log(dbConf);

The only thing left to do before you run is install confim: npm i -S confim

Now try running the example: node index.js; When you try to run it in the production environment it will throw an error as the database password is not set: env NODE_ENV=production node index.js; This can be fixed by supplying the variable: env NODE_ENV=production DATABASE_password=yay! node index.js

Need help?

Just create an issue on GitHub and I will see what I can do...

Future plans

  • Nicer error handling
  • Translate keys to multi-level objects