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

rob-config

v6.0.0

Published

Robust configuration package for nodejs, built on top of convict

Downloads

1,276

Readme

rob-config

NPM version node-current Build Status

Robust configuration module for nodejs, built on top of convict.

Installation

npm install rob-config --save

Why another config package?

config is a very simple and powerfull config package but it lacks from schema and validation.

convict is not simple to use, but way more robust and overridable.

So I wanted something:

  • Easy to use like config
  • With schema and documentation like convict
  • With possibility to override with env variable or command line argument like convict
  • With a command to validate config for dev AND before deployment to production
  • With a command to see the builded config depends on env and default value (easier to debug)

Here it is and it's very easy to migrate from config or convict.

Usage

Define a config schema, simple object.

See https://github.com/mozilla/node-convict#the-schema for documentation about schema definition.

For example: config/schema.js

module.exports = {
    env: {
        doc: 'The applicaton environment.',
        format: ['production', 'staging', 'integration', 'development', 'test'],
        default: 'development',
        env: 'NODE_ENV',
    },
    api: {
        port: {
            doc: 'The API port',
            format: 'port',
            default: 3000,
        },
        timeout: {
            doc: 'The API timeout',
            format: 'nat',
            default: 60 * 1000, // 1 minutes
        },
    },
};

Then, define the first config file.

For example: config/development.js

module.exports = {
    api: {
        port: 3001, // test with "nothing" value to see validation error
    },
};

You can, optionnaly, define a config/formats.js to add one or more custom format to convict.

See https://github.com/mozilla/node-convict#custom-format-checking for documentation about custom formats.

convict.addFormats() will be call under the hood.

For exemple: config/formats.js

module.exports = {
    'float-percent': {
        validate: function (val) {
            if (val !== 0 && (!val || val > 1 || val < 0)) {
                throw new Error('must be a float between 0 and 1, inclusive');
            }
        },
        coerce: function (val) {
            return parseFloat(val, 10);
        },
    },
};

Display your builded configuration

Run ./node_modules/.bin/rob-config show:

Display final configuration

Validate your configuration against schema

Run ./node_modules/.bin/rob-config validate:

Validate configuration ok

In case of error:

Validate configuration error

Display the schema description

Run ./node_modules/.bin/rob-config describe:

Schema description

Use it in your project

const config = require('rob-config');

console.log(config.get('api.port'));

Change config dir

You can set env variable ROB_CONFIG_DIR with the relative path of your project configuration directory.

Versioning

To keep better organization of releases we follow the Semantic Versioning 2.0.0 guidelines.

See Releases for detailed changelog.

License

MIT License © Jérôme Macias