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 🙏

© 2026 – Pkg Stats / Ryan Hefner

konfiguration

v1.1.3

Published

Create config from config files and environment variables

Readme

konfiguration

Version Build Status Coverage License

Configuration package for Node projects. Define your default configuration settings in YAML files and easily override/extend them using environment-specific files as well as environment variables.

Quick start

yarn add konfiguration
# OR
npm install konfiguration --save

mkdir config
vi config/database.yaml
database:
  username: user
  password: test
  hostname: localhost

Override settings for production (using file)

vi config/database.production.yaml
# OR
mkdir config/production
vi config/production/database.yaml
database:
  hostname: prod-1.us-west-2.rds.amazonaws.com

Override settings for production (using environment variables)

export DATABASE__HOSTNAME=prod-1.us-west-2.rds.amazonaws.com
export DATABASE__PASSWORD=prodpass

Use config values in the app code

import config from 'konfiguration';

database.connect(config.get('database'));

About konfiguration

This package merges together configuration settings from general YAML-formatted config files, environment-specific YAML-formatted config files, and environment variables (in that order) to create a final application config that can used throughout your code. The environment is determined from the NODE_ENV environment variable and defaults to development if none is specified.

Configuration files

Configuration files can be stored in a directory of your choice. The default directory is ./config, but you can use the NODE_CONFIG_DIR environment variable to specify any location. All YAML files contained in the directory will be parsed and merged together, so it is entirely up to you how you want to structure your config files (e.g. a single file or a file per module).

Environment-specific configuration files

Environment-specific YAML files contained in the config directory will only be merged in if the current environment matches. They can be placed in the root of the config directory and named {filename}.{env}.yaml, or they can be placed into a subdirectory {env}/{filename}.yaml.

Environment variables

Environment variables are merged into the configuration after all files are loaded. They are type-cast to match the value in the configuration files, if one exists (e.g. if you have port: 3000 in a config file and an environment variable PORT=80 will be merged in to the port key as 80 despite being "80" in process.env).

NODE_CONFIG

The first environment variable that gets merged in is NODE_CONFIG, which must be a JSON-formatted string. This single environment variable allows you to override as much or as little of your config as you like.

Others

Then, other environment variables are merged in. Names are converted to camelCase and object dot-notation using the following rules: __ becomes a . for nesting and _ becomes a capital letter. For example, the environment variable DATABASE__USER_NAME would override config.database.userName.

Optionally, you can also specify an environment variable prefix using NODE_CONFIG_PREFIX, which filters the environment variables that will be merged. The prefix will be stripped when the name is converted for merging. For example, if you have NODE_CONFIG_PREFIX="APP_", only environment variables matching APP_* would be merged (e.g. APP_DATABASE__USER_NAME -> config.database.userName).

Usage

Now that all files and environment variables have been merged together, your config is ready to use throughout your application code. All properties can be accessed directly:

import config from 'konfiguration';

console.log(config.database.userName);

But there are various helper functions on the config class that can make things easier.

config.environment()

Quickly check if you are running in one or more environments by passing them as arguments to config.environment:

import config from 'konfiguration';

if (config.environment('development', 'production')) {
  // Either in development or production environment
}

config.get()

Quickly access config values using dot-notation or return a supplied default value if the key does not exist:

import config from 'konfiguration';

config.get('database'); // returns config.database
config.get('maybe.undefined', 'default_value'); // returns config.maybe.undefined or 'default_value' if undefined

config.set()

Easily change config values using dot-notation:

import config from 'konfiguration';

config.set('database.userName', 'test');
config.get('database.userName'); // returns 'test'