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

ms-conf

v8.2.1

Published

wrapper over dotenv and nconf module for one line configuration loading

Downloads

475

Readme

Configuration loading module

Combines confidence, dotenv, nconf and processes env configuration into camelcase; Each value is JSON parsed first if it is possible, therefore you can pass arrays/objects and boolean params through env

Installation

npm i ms-conf or any other manager

Configuration

Accepts following configuration params, which can be passed through .env or process.env

  1. DOTENV_NOT_SILENT - if present, warnings from dotenv wont be supressed
  2. DOTENV_ENCODING - defaults to 'utf-8'
  3. DOTENV_FILE_PATH - if .env file isn't located in the root of your module, you can pass path here
  4. NCONF_SEPARATOR - defaults to __
  5. NCONF_MATCH - only envs, matched by this would be returned through configuration
  6. NCONF_MATCH_OPTS - opts for regexp constructed from NCONF_MATCH
  7. NCONF_WHITELIST - stringified JSON array of variebles that should be parsed into final configuration
  8. NCONF_FILE_PATH - external JSON configuration file that will be used to provide variables
  9. NCONF_NAMESPACE - MUST be specified, as it will return configuration relative to this namespace
  10. NCONF_NO_CAMELCASE - if present, keys will not be camelCased

Usage

.env file:

NCONF_NAMESPACE=MS_CONF
NCONF_MATCH=^MS_CONF
NCONF_MATCH_OPTS=i
MS_CONF__AMQP__HOSTS=["127.0.0.1"]
MS_CONF__AMQP__SSL=true
MS_CONF__AMQP__STRING_TRUE='"true"'
NCONF_FILE_PATH=["/etc/app-configs","/etc/nice-config.js","/opt/app/bundle.json"]
// ESM
import { Store } from 'ms-conf';
// CJS
const { Store } = require('ms-conf');

// get basic configuration
const store = new Store()
const config = store.get('/');
// config would equal
// {
//   amqp: {
//     hosts: ['127.0.0.1'],
//     ssl: true,
//     stringTrue: 'true'
//   }
// }

store.get('/amqp') // will return inner object and so on
store.get('/amqp/hosts') // ['127.0.0.1']

Hot Reload

store.enableReload();
// send SIGUSR1 or SIGUSR2 signal to process to reload configuration

store.disableReload();
// wont listen for SIGUSR1 or SIGUSR2 events any longer

Utilities

  1. Load file path
// CJS
const { globFiles } = require('ms-conf');
// ESM
import { globFiles } from 'ms-conf';

// generates config for the passed files bypassing public API
const config = globFiles(
  undefined, // prependFile: string | undefined,
  ['/path/to/configs', '/path/to/config/direct.js', '/path/to/conf.json'], // fileList: string | string[]
  {}, // config: baseConfig
  true, // throw error in case of file processing issues
);
  1. setDefaultOpts
// define default options
const store = new Store({ defaultOpts: { env: process.env.NODE_ENV } })

// change default opts in runtime
store.opts.defaultOpts = { env: process.env.NODE_ENV }
  1. prependDefaultConfiguration

Pass absolute filepath, which would be prepended. Useful to pass a directory with bundled default config

store.prependDefaultConfiguration(filePath);
  1. crash when configuration files can't be loaded

in 8+ behavior changes and malformed configuration files are not ignored anymore. To disable this set crashOnError option to false`

const { Store } = require('ms-conf');

const store = new Store({ crashOnError: false })
conf.prependDefaultConfiguration(['/path/to/config.json']);
conf.get('/path') // wont throw errors on malformed files, but will write into stderr notifying of the error

For a more detailed example - see tests