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

@capnajax/default-config

v3.0.3

Published

Per-env config with defaults

Downloads

28

Readme

default-config

Per-env config with defaults

Installation

npm install --save @capnajax/default-config
import c from '@capnajax/default-config';

c('config.path');

Usage

Upon startup, this module obtain a config file from one of these places, in order of priority:

  1. A location specified by a --config=<filename> parameter,
  2. A location specified by a CONFIG_PATH environment variable,
  3. ${PWD}/config-${CONFIG_ENV}.yaml
  4. ${PWD}/config-${NODE_ENV}.yaml
  5. ${PWD}/config.yaml

Multiple config files can be used by separating them with the system path delimiter (e.g. on POSIX --config=./config.yaml:./secrets/secret-config.yaml). When there are multiple files in the path have values for the same key, the last one takes precedent.

Also, it will load a default-config.yaml from the entry point module's directory. This file specifies default configurations. Other config files will override the configs in this one.

This will also get an environment name from one of these places, also in order of priority:

  1. As specified by a --env=<envname> parameter,
  2. As specified by a CONFIG_ENV environment variable,
  3. As specified bt a NODE_ENV environment variable, or
  4. Default value of local.

Note that when configs are loaded, they are loaded using syncronous methods.

The config file(s)

A config file is a YAML file with two sections, default and environments. The envornments section has a section for each environment name.

The default-config.yaml file does not have an environments section. Anything in an environments section in the default-config.yaml will be ignored.

Configs are loaded in this order of priority:

  1. The config file's environments.<environment name> section,
  2. The config file's default section, or
  3. The default config file's default section.

Example config file

config.yaml:

default:
  // overrides configs in the default-config.yaml below.
  animal: wildebeest
  plural: wildebeests
  // collective-noun inherited from default-config.yaml
environment:
  // because local is not specified, if env is not specified, it'll use the default.
  dev:
    // overrides the default configs.
    animal: moose
    plural: moose
    // collective-noun inherited from default 
  qa:
    animal: octopus
    plural: octopodes
    collective-noun: shoal
  prod:
    animal: goose
    plural: geese
    collective-noun: flock

default-config.yaml

default:
  animal: bison
  plural: bisons
  collective-noun: herd
// note there is only a default section, no evironments section

Changes from v2.x to v3.x

  • Support for multiple config files.
  • There is no automatic checking for default-config.yaml.

Changes from v1.x to v2.x

  • Converted from a CommonJS to an ES6 module
  • The default config file is now in the current working directory, not the directory of the entry point module.