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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@onlineapps/runtime-config

v1.0.2

Published

Runtime configuration resolver with schema-driven priority (explicit config → ENV → owner defaults)

Readme

@onlineapps/runtime-config

Runtime configuration resolver with schema-driven priority.

Features

  • Single mechanism: One resolver for all runtime config resolution
  • Schema-driven: Each module declares its config schema once
  • Priority order: explicit config → ENV → owner defaults
  • Fail-fast: required: true throws if value missing
  • Type coercion: Auto-parses strings to number/boolean

Installation

npm install @onlineapps/runtime-config

Usage

const { createRuntimeConfig } = require('@onlineapps/runtime-config');
const DEFAULTS = require('./defaults');

const runtimeCfg = createRuntimeConfig({
  defaults: DEFAULTS,
  schema: {
    host:     { env: 'REDIS_HOST', defaultKey: 'defaultHost' },
    port:     { env: 'REDIS_PORT', defaultKey: 'defaultPort', type: 'number' },
    password: { env: 'REDIS_PASSWORD' },
    ttl:      { env: 'CACHE_TTL', defaultKey: 'defaultTTLSeconds', type: 'number' },
    // Infra topology - FAIL-FAST (no default)
    url:      { env: 'REDIS_URL', required: true },
  }
});

// Get single value
const host = runtimeCfg.get('host');

// Resolve all with explicit overrides
const config = runtimeCfg.resolve({ password: 'secret' });

Priority Order

  1. Explicit config: Value passed to resolve() or get()
  2. Environment variable: process.env[spec.env]
  3. Owner defaults: Value from defaults object

Schema Spec Properties

| Property | Type | Description | |----------|------|-------------| | env | string | Environment variable name | | defaultKey | string | Key in defaults object | | default | any | Inline default value | | type | string | Value type: 'string', 'number', 'float', 'boolean' | | required | boolean | If true, throws when value is missing |

Type Coercion

  • number: Parses with parseInt(), throws on invalid
  • float: Parses with parseFloat(), throws on invalid
  • boolean: Accepts true, false, 'true', 'false', '1', '0'
  • string: Converts to string

Fail-Fast for Infra Topology

For infrastructure URLs/hosts, use required: true without defaults:

const runtimeCfg = createRuntimeConfig({
  defaults: {},
  schema: {
    rabbitmqUrl: { env: 'RABBITMQ_URL', required: true },
    redisUrl: { env: 'REDIS_URL', required: true },
  }
});

// Throws if RABBITMQ_URL or REDIS_URL are not set
const config = runtimeCfg.resolve();

Naming Convention

  • ServiceConfig = biz-specific config (per-service, loaded by ServiceConfigLoader)
  • RuntimeConfig = runtime config (env/defaults, resolved by this library)

API

createRuntimeConfig(options)

Creates a new resolver instance.

Options:

  • defaults (Object): Owner defaults object
  • schema (Object): Config schema definition
  • env (Object): Environment object (defaults to process.env)

Returns: RuntimeConfigResolver instance

resolver.get(key, [explicitValue])

Get a single config value.

Parameters:

  • key (string): Config key name
  • explicitValue (any): Explicit value (highest priority)

Returns: Resolved value

Throws: Error if key is unknown or required value is missing

resolver.resolve([explicitConfig])

Resolve all config values at once.

Parameters:

  • explicitConfig (Object): Explicit config object (highest priority)

Returns: Object with all resolved config values

Throws: Error if any required value is missing

resolver.keys()

Get all schema keys.

Returns: Array of config key names

resolver.has(key)

Check if a key exists in schema.

Returns: Boolean