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

@cortec/config

v2.4.1

Published

<description>

Readme

@cortec/config

Module Overview

@cortec/config provides configuration management for Cortec modules. It wraps the config library and adds runtime schema validation using zod. This ensures that configuration values are present and correctly typed, with helpful error messages if validation fails.

The module exposes both a legacy interface (CortecConfig) and a static utility class (Config) for retrieving and validating configuration values.

Configuration Options

Where to put config

Place your configuration files in the config/ directory of your project (e.g., config/default.yml, config/production.yml). Each module expects its own section in the config file.

How config is loaded

The config is loaded automatically by the @cortec/config module (using the config library). You access config values in code using:

import { Config, z } from '@cortec/config';

const schema = z.object({
  host: z.string(),
  port: z.number(),
  password: z.string().optional(),
});
const redisConfig = Config.get('redis', schema);

If the configuration is missing or invalid, an error is thrown with details.

API

Config.get<T>(path: string, schema?: z.Schema<T>): T
  • path: The configuration key or path (e.g., "redis", "server.http").
  • schema: A zod schema describing the expected structure and types.

Example YAML

redis:
  host: 'localhost'
  port: 6379
  password: 'secret'
server:
  http:
    port: 8080

Field-by-field explanation

  • Each top-level key (e.g., redis, server) represents a module or feature.
  • The structure under each key is determined by the module's requirements.
  • Use a zod schema to validate the expected structure and types for each config section.

What happens if config is missing or invalid

  • If a config value is missing, Config.get throws an error with a helpful message.
  • If a config value does not match the provided schema, a validation error is thrown with details about the mismatch.

Example Usage

Basic Usage

import { Config, z } from '@cortec/config';

// Define a schema for your config
const redisSchema = z.object({
  host: z.string(),
  port: z.number(),
  password: z.string().optional(),
});

// Retrieve and validate config
const redisConfig = Config.get('redis', redisSchema);

console.log(redisConfig.host, redisConfig.port);

Handling Missing or Invalid Config

try {
  const serverConfig = Config.get(
    'server',
    z.object({
      http: z.object({
        port: z.number(),
      }),
    })
  );
  console.log('Server will run on port', serverConfig.http.port);
} catch (err) {
  console.error('Config error:', err.message);
}

Listing Config Sources

const sources = Config.files();
console.log('Loaded config files:', sources);

Legacy Interface

For backward compatibility, you can use the CortecConfig class:

import CortecConfig from '@cortec/config';

const config = new CortecConfig();
const value = config.get('some.path');

Note: The legacy interface does not perform schema validation.

Best Practices

  • Always define and use a zod schema for your configuration to catch errors early.
  • Organize your config files by environment (e.g., default.yml, production.yml).
  • Use Config.files() to debug which config files are being loaded.

References