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

@myob-oss/config

v1.0.8

Published

A simple, slightly opinionated, and predictable configuration module for Node.js applications.

Downloads

689

Readme

@myob-oss/config

A simple, slightly opinionated, and predictable configuration module for Node.js applications.

To install the module in your project use the following command.

npm install @myob-oss/config

To use the module (after you have installed it in your project), you only need to require it, and it exposes the configuration as an Object.

const config = require('@myob-oss/config');

console.log(config.configurationFile); // prints "runtime" from the example below.

Yes, this is another configuration module. We know there are others out there. We created this configuration module to simplify and unify the way in which we configured our node applications to work with our various environments including our cloud infrastructure, continuous delivery pipelines and running our apps locally.

The benefits we have seen from using this configuration module are:

  • A consistent way to enable environmentally-aware configuration across a suite of node applications.
  • Easy to use, just require the module and there is your configuration ready to use.
  • Doesn't force you to repeat configuration that is consistent across all environments.
  • Easy to see the running config file by inspecting the runtime.json file. (Works great for just shelling in a taking a look!)

This configuration module has also been mentioned in the Under The Hood series of blog posts.

How the Configuration Hierarchy Works

This module uses the environment variable NODE_ENV to determine which configuration file to load.

The module assumes that all the configuration files are in JSON format and in the /config folder at the top level of the project. The JSON files can have comments in them, as the module uses the json5 module to parse the config files.

The module loads 3 configuration files in the following order (each overwrites the previous if they have the same key):

  • default.json
  • environment.json (where environment is taken from the NODE_ENV environment variable. It uses "production" as default if the environment variable is not set)
  • runtime.json

Each configuration file will override values from the previous file. For example:

default.json

{
  "configurationFile": "default",
  "disableConsole": false
}

production.json

{
  "debugLevel": "trace"
}

runtime.json

{
  "configurationFile": "runtime",
  "validHosts": ["localhost", "example.com"]
}

The resulting configuration will be:

{
  "configurationFile": "runtime",
  "disableConsole": false,
  "validHosts": ["localhost", "example.com"],
  "debugLevel": "trace"
}

This uses the deepmerge module to do the merging of the configuration objects.

Testing

To run the tests use the following command.

npm test

Code Coverage

To run the coverage scanner and generate coverage report use the following command. It fails if the threshold coverage has not passed. The threshold settings are stored in the file .nycrc. Please note that the thresholds configured are per-file.

npm run cover

Linting

To run the linting check run the following command.

npm run lint