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

confure

v0.1.2

Published

Zod-native, type-safe configuration for Node services — one descriptor yields a validated, defaulted, env-bound value with secret redaction and fail-fast production guards.

Readme

confure

Zod-native, type-safe configuration for Node services. Declare each setting once — with its env var, default, docs, and secrecy — and get back a validated, defaulted, env-bound value object with end-to-end inferred types, secret redaction, and fail-fast production guards.

confure turns one declarative descriptor into three things: a Zod validation schema, a defaults object, and the environment-variable bindings. Layers merge in a fixed precedence (defaults → per-env files → .env.local → env vars) and collapse into one .parse() at boot — coercion included. Because the value type is inferred from the descriptor, config.get('jwt.secret') is checked — both the path and the return type — at compile time. No hand-written interfaces, no unchecked string reads.

Install

npm install confure
# or: yarn add confure

Requires Node >=18. zod is a runtime dependency. @nestjs/common/@nestjs/core are optional — only the confure/nest subpath imports them.

Usage

Declare the shape once, then read it typed:

import { cf, withConfig } from 'confure';

const config = withConfig(
  {
    env: cf.enum({
      env: 'NODE_ENV',
      values: ['development', 'test', 'staging', 'production'] as const,
      default: 'development',
      doc: 'Runtime environment',
    }),
    service: {
      name: cf.string({ env: 'SERVICE_NAME', default: 'app' }),
      port: cf.port({ env: 'PORT', default: 3000 }),
    },
    postgres: {
      url: cf.url({ env: 'PG_URL', default: 'postgres://postgres:postgres@localhost:5432/app' }),
    },
    jwt: {
      secret: cf.string({ env: 'JWT_SECRET', default: '', sensitive: true, requiredInProd: true }),
    },
  },
  { dir: import.meta.dirname }, // enables per-env JSON files + .env.local; optional
);

config.get('service.port'); // number — compile error if the path is wrong
config.getAll(); // the whole validated, typed object
config.toSafeJSON(); // same object, `jwt.secret` → "[redacted]"

Precedence (low → high): defaults → {env}.json → {env}.local.json → env vars → parse. Coercion lives in each builder's schema, so env strings become numbers/booleans/arrays in the single fail-fast pass.

Sections compose and override cleanly:

import { withConfig } from 'confure';
import { postgres, service } from 'confure/presets';

const config = withConfig({
  ...service({ name: { default: 'billing' } }),
  ...postgres({ url: { env: 'PG_URL_2' } }),
});

NestJS users opt into DI without pulling framework code into the core:

import { createConfigModule, InjectConfig } from 'confure/nest';
import type { Config } from 'confure';

@Module({ imports: [createConfigModule(config)] })
export class AppModule {}

@Injectable()
class Billing {
  constructor(@InjectConfig() private readonly config: Config<AppConfig>) {}
}

What's in here

Core (confure)

  • cf — field builders: string, number, boolean, port, enum, array, url, base64, and object (plus plain nesting). Each takes { env?, default?, doc?, sensitive?, requiredInProd? } and returns a ConfigField<T> whose value type flows into the inferred config object.
  • withConfig(descriptor, opts?) — returns a typed Config<T>:
    • get(path) — compile-time-checked dot path + return type;
    • getAll() / raw() — the whole validated object;
    • toSafeJSON() — deep clone with every sensitive leaf masked.
  • ConfigOptionsdir, env, files, dotenvLocal, strict, redactValue, onInsecureProd, and a refine hook (a consumer superRefine for conditional validation, e.g. driver === 's3' ⇒ s3.bucket required).
  • EnginebuildZodSchema (strict-by-default z.strictObject), buildDefaults, buildEnvBindings: the three structures derived from one descriptor.
  • FilesresolveConfigDir (dist-vs-src fallback), loadConfigFiles ({env}.json then {env}.local.json).
  • .env.local loaderloadLocalDevEnv: once-per-process, non-clobbering, test-runner-aware, walks up to a configurable root marker (default package.json/nx.json).
  • SectionsmergeSection + SectionOverrides<S> for building reusable, override-friendly config sections.

Guards (production hygiene)

  • RedactiontoSafeJSON() masks sensitive leaves in any serialization, so JSON.stringify(config.toSafeJSON()) is log-safe.
  • requiredInProd — refuses to boot when a flagged field is empty or still equals its insecure declared default in production (throw by default, warn opt-in). Fail-fast on the classic "shipped the dev secret" bug.
  • Strict-by-default — unknown keys in descriptors/files throw at boot; opt out with strict: false.

Optional subpaths

  • confure/nestcreateConfigModule(config) (a @Global module), the CONFURE_CONFIG token, and InjectConfig().
  • confure/presets — generic service, postgres, redis, logger, observability sections with placeholder defaults (no service topology; override the values for your deployment).

Design

See DESIGN.md for the goals, the descriptor engine, and the rationale behind each decision.


MIT © confure contributors