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

@spirex/config-provider-env

v1.0.0

Published

Environment variable provider for @spirex/config — maps process.env into layered configuration

Readme

@spirex/config-provider-env

npm version License: MIT TypeScript

@spirex/config-provider-env bridges process.env with the @spirex/config provider interface. It reads environment variables, maps __ (double underscore) to : section separators, optionally filters by a prefix, and integrates cleanly into a layered configuration stack.

Note: This package is an extension. You need @spirex/config to use it.

Why use this provider?

  • Seamless process.env integration — turn environment variables into typed configuration values.
  • Prefix filtering — scope env vars to your app, e.g. APP_.
  • Optional prefix stripping — remove the prefix so config keys stay clean.
  • Automatic section mappingAPP_DB__HOST becomes db:host for use with config.section("db").
  • Case-insensitive lookupsconfig.getString("db:host") works regardless of env casing.
  • Hot reload support — call config.reload() to re-read process.env at runtime.
  • First-class TypeScript support — full declarations included.
  • Zero runtime dependencies.

Installation

This package has a peer dependency on @spirex/config, so install both:

# npm
npm install @spirex/config @spirex/config-provider-env

# yarn
yarn add @spirex/config @spirex/config-provider-env

# pnpm
pnpm add @spirex/config @spirex/config-provider-env

Quick start

import { configBuilder } from "@spirex/config";
import { InMemoryConfigProvider } from "@spirex/config/in-memory";
import { EnvConfigProvider } from "@spirex/config-provider-env";

const config = configBuilder()
  // Built-in defaults
  .add(
    new InMemoryConfigProvider({
      db: { host: "localhost", port: "5432" },
      features: { darkMode: "false" },
    }),
  )
  // Environment overrides, e.g. APP_DB__HOST=prod.example.com
  .add(new EnvConfigProvider("APP_", true))
  .build();

const db = config.section("db");
const host = db.getString("host"); // "prod.example.com" from env, or "localhost" default
const port = db.getInteger("port"); // 5432
const darkMode = config.getBoolean("features:darkMode");

Documentation

new EnvConfigProvider(prefix?, stripPrefix?)

Creates a provider that reads from process.env.

| Argument | Type | Default | Description | | --- | --- | --- | --- | | prefix | string | — | Optional prefix used to filter environment variables. Only keys starting with this prefix are loaded. | | stripPrefix | boolean | false | When true, the prefix is removed from the resulting configuration key. |

import { EnvConfigProvider } from "@spirex/config-provider-env";

// Loads every environment variable
const all = new EnvConfigProvider();

// Loads only variables starting with "APP_"
const prefixed = new EnvConfigProvider("APP_");

// Loads "APP_" variables and strips the prefix from keys
const stripped = new EnvConfigProvider("APP_", true);

Section mapping

Double underscores in environment variable names become section separators.

| Environment variable | Config key (after strip) | Access pattern | | --- | --- | --- | | APP_DB__HOST | db:host | config.section("db").getString("host") | | APP_A__B__C | a:b:c | config.getString("a:b:c") or config.section("a:b").getString("c") | | APP_HOST | host | config.getString("host") |

Case-insensitive lookups

Lookups are performed in lowercase, so the following all return the same value:

config.getString("db:host");
config.getString("DB:HOST");
config.section("DB").getString("HOST");

Prefix filtering

Use a prefix to avoid accidentally loading unrelated environment variables:

process.env.APP_HOST = "0.0.0.0";
process.env.PATH = "/usr/bin";

const provider = new EnvConfigProvider("APP_", true);
provider.load();

provider.get("host"); // "0.0.0.0"
provider.get("PATH"); // undefined
provider.get("path"); // undefined

Reloading

@spirex/config calls load() automatically when you invoke builder.build(). To pick up changes later, call config.reload():

process.env.APP_LOG_LEVEL = "debug";
config.reload();

const level = config.getString("log:level"); // "debug"

Integration with @spirex/config

Add the provider to any configBuilder() stack. Because later providers override earlier ones, environment variables naturally take precedence over file or in-memory defaults.

import { configBuilder } from "@spirex/config";
import { InMemoryConfigProvider } from "@spirex/config/in-memory";
import { EnvConfigProvider } from "@spirex/config-provider-env";

const config = configBuilder()
  .add(new InMemoryConfigProvider({ server: { port: "3000" } })) // defaults
  .add(new EnvConfigProvider("APP_", true)) // environment overrides
  .build();

const port = config.getInteger("server:port");

Using multiple environment providers

You can register several EnvConfigProvider instances in the same configuration stack — for example, to merge application settings with infrastructure or third-party service variables.

const config = configBuilder()
  .add(new EnvConfigProvider("APP_", true))
  .add(new EnvConfigProvider("INFRA_", true))
  .build();

// APP_DB__HOST=localhost and INFRA_REGION=us-east-1
config.getString("db:host"); // "localhost"
config.getString("region"); // "us-east-1"

Later providers override earlier ones when keys collide, following the standard @spirex/config priority rules.

API reference

| Member | Description | | --- | --- | | new EnvConfigProvider() | Loads all environment variables. | | new EnvConfigProvider(prefix) | Loads variables filtered by prefix; keeps prefix in keys. | | new EnvConfigProvider(prefix, true) | Loads filtered variables and strips the prefix. | | provider.load() | Reads process.env into the internal cache. | | provider.get(key) | Returns the value for a key (case-insensitive). |

TypeScript

@spirex/config-provider-env ships with TypeScript declarations. No extra @types package is required.

License

@spirex/config-provider-env is released under the MIT License.