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

config-plus

v0.1.1

Published

Merge 2 configurations, merge configuration with environment variables

Readme

config-plus

A lightweight TypeScript library for merging configuration from multiple sources:

  1. Default Configuration
  2. Environment Configuration (SIT, UAT, PRD)
  3. Environment Variables (process.env)

Configuration is merged in the following order:

          Default Configuration
                   │
                   ▼
Environment Configuration (SIT, UAT, PRD)
                   │
                   ▼
   Environment Variables (process.env)
                   │
                   ▼
          Final Configuration

Environment variables always have the highest priority


Features

  • Recursive config merging
  • Environment overrides (SIT, UAT, PRD)
  • Environment variables overrides (process.env)

Examples:

REST API

Import Data

Export Data

Message Queue


Strengths

  • 🚀 Zero dependencies
  • 📦 Lightweight and fast
  • 🔷 Written in TypeScript
  • 🔒 Strongly typed API
  • 🔄 Deep object merge
  • ✅ Automatic parsing of:
    • string
    • number
    • boolean
    • array (JSON)
  • 📋 Array override support

Installation

npm install config-plus

or

yarn add config-plus

Why?

Most applications need configuration from multiple sources.

For example:

  1. Default configuration
export const config = {
  server: {
    port: 8000,
    host: "localhost",
  },
  database: {
    host: "localhost",
    port: 5432,
  },
}
  1. UAT overrides and PRD overrides for the configuration
export const environments = {
  uat: {
    server: {
      port: 8080,
    },
  },
  prd: {
    server: {
      port: 80,
    },
    database: {
      port: 5431,
    },
  },
}
  1. Environment variables
SERVER_PORT=443
DATABASE_HOST=db.company.com

The library automatically combines all of them into a single configuration object.


Quick Start

import { merge } from "config-plus"

export const config = {
  server: {
    port: 8000,
    host: "localhost",
  },
  database: {
    host: "localhost",
    port: 5432,
  },
}

// SIT overrides and PRD overrides for the configuration
export const environments = {
  uat: {
    server: {
      port: 8080,
    },
  },
  prd: {
    server: {
      port: 80,
    },
    database: {
      port: 5431,
    },
  },
}

const cfg = merge(config, process.env, environments, "prd")

when

SERVER_PORT=443
DATABASE_HOST=db.company.com

Result:

{
  server: {
    host: "localhost",
    port: 443
  },
  database: {
    host: "db.company.com",
    port: 5431
  }
}

Architecture

merge()
    │
    ├── mergeEnvironments()
    │
    └── mergeEnv()
             │
             ▼
        mergeWithPath()

Type handling

This is one of the strongest parts.

It automatically converts environment variables based on the existing property's type.

Strings

"localhost"

↓

HOST="google.com"

↓

"google.com"

Numbers

8080

↓

PORT=3000

↓

3000

with validation.

Boolean

false

↓

SSL=true

↓

true

Arrays

Allows

STATUS=["A","B","C"]

using JSON parsing.

Many libraries don't support arrays.

Objects

Recursive

db.user

↓

DB_USER

Naming convention

Environment names become

db.host

↓

DB_HOST

and

cache.redis.timeout

↓

CACHE_REDIS_TIMEOUT

This is an industry-standard convention

Configuration acts as schema

Instead of

{
    type: Number,
    default: 8080
}

simply write

port: 8080

The runtime infers

number

Very elegant.

No decorators

Supported Types

Current implementation supports

  • string
  • number
  • boolean
  • object
  • array

Not supported

  • ❌ bigint
  • ❌ Date
  • ❌ Map
  • ❌ Set
  • ❌ enum
  • ❌ null override
  • ❌ undefined override

API

merge()

merge(
  config: { [key: string]: any },
  env: ProcessEnv,
  environments?: { [key: string]: { [key: string]: any } },
  environmentName?: string,
  logError?: (msg: string) => void,
  logInfo?: (msg: string) => void,
): { [key: string]: any };

Merges:

  • default configuration
  • environment configuration (SIT, UAT, PRD)
  • process environment variables

Example

const config = merge(defaults, process.env, environments, "uat")

mergeEnvironments()

mergeEnvironments(config, environmentConfig)

Deep merges an environment configuration into the default configuration.

Example

mergeEnvironments(defaultConfig, productionConfig);

mergeEnv()

mergeEnv(config, process.env)

Overrides configuration values using environment variables.


mergeWithPath()

Internal recursive merge function.

Normally you should call merge() instead.


Environment Variable Mapping

Nested properties are converted into uppercase environment variables.

Configuration

{
    server:{
        port:8080
    }
}

becomes

SERVER_PORT

More examples

| Configuration | Environment Variable | | -------------------- | -------------------- | | database.host | DATABASE_HOST | | database.port | DATABASE_PORT | | database.pool.size | DATABASE_POOL_SIZE | | logging.level | LOGGING_LEVEL |


Supported Types

String

{
    host:"localhost"
}
HOST=myserver

host = "myserver"

Number

{
    port:8080
}
PORT=9090

port = 9090

Boolean

{
    ssl:false
}
SSL=true

ssl = true

Only the literal value "true" enables the option.


Arrays

Arrays must be valid JSON.

SERVERS=["a","b","c"]

servers = [
    "a",
    "b",
    "c"
]

Nested Objects

Nested objects are merged recursively.

Default

{
    database:{
        host:"localhost",
        port:5432
    }
}

Override

{
    database:{
        host:"production-db"
    }
}

Result

{
    database:{
        host:"production-db",
        port:5432
    }
}

Example

Quick example:

const defaults = {
    server: {
        host: "localhost",
        port: 8080
    },
    database: {
        host: "localhost",
        port: 5432
    }
};

const environments = {
    uat: {
        server: {
            port: 80
        }
    }
};

process.env.SERVER_HOST = "0.0.0.0";
process.env.DATABASE_HOST = "db.company.com";

const config = merge(defaults, process.env, environments, "uat");

Result

{
    server: {
        host: "0.0.0.0",
        port: 80
    },
    database: {
        host: "db.company.com",
        port: 5432
    }
}

Best Practices

  • Keep default values in your configuration file.
  • Store secrets in environment variables.
  • Use environment-specific configuration for deployment differences.
  • Avoid hardcoding credentials.
  • Commit only default configuration to source control.

Limitations

Current implementation does not support:

  • custom value parsers
  • enum parsing
  • Date objects
  • Map / Set
  • immutable merging

These features may be added in future versions.


Comparison with popular libraries


Why config-plus

Many configuration libraries include features such as file loading, validation, schemas, plugins, and dependency injection. While powerful, they can be unnecessary for smaller projects or reusable libraries.

config-plus focuses on one job:

  • merging configuration objects,
  • applying environment-specific overrides,
  • overriding values from process.env

The result is a tiny, dependency-free utility that is easy to understand, easy to maintain, and suitable for applications, libraries, and frameworks.

Recommended Usage

This library is best suited for:

  • Microservices
  • REST APIs
  • Batch jobs
  • Internal backend applications
  • Docker/Kubernates deployments

License

MIT