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

@sailboat-computer/config-loader

v1.1.56

Published

Configuration loader for sailboat computer services

Readme

Configuration Loader

A configuration loader for the Sailboat Computer system that provides:

  • Loading configuration from JSON files
  • Validating configuration against JSON schemas
  • Watching for configuration changes
  • Environment variable overrides
  • Default values
  • Configuration versioning and rollback support

Installation

npm install @sailboat-computer/config-loader

Usage

Basic Usage

import { loadConfig } from '@sailboat-computer/config-loader';

// Load configuration with default values
const config = await loadConfig<MyConfig>(
  'my-service/config.json',
  defaultConfig
);

// Use configuration
console.log(config.someValue);

With Validation

import { loadConfig } from '@sailboat-computer/config-loader';

// Load configuration with validation
const config = await loadConfig<MyConfig>(
  'my-service/config.json',
  defaultConfig,
  { validate: true }
);

// The loader will automatically look for 'my-service/config.schema.json'
// and validate the configuration against it

Watching for Changes

import { createConfigLoader } from '@sailboat-computer/config-loader';

// Create a loader with watching enabled
const loader = createConfigLoader({ watch: true });

// Load configuration
const config = await loader.load<MyConfig>('my-service/config.json');

// Watch for changes
loader.watch('my-service/config.json', (event) => {
  console.log('Configuration changed:', event.config);
});

Environment Variable Overrides

The configuration loader supports overriding configuration values using environment variables. The environment variable names are constructed as follows:

CONFIG_<PATH>_<KEY>

Where:

  • <PATH> is the configuration file path with slashes and dots replaced by underscores and converted to uppercase
  • <KEY> is the configuration key with dots replaced by underscores and converted to uppercase

For example, to override the database.host value in the my-service/config.json file, you would set the environment variable:

CONFIG_MY_SERVICE_CONFIG_DATABASE_HOST=localhost

Saving Configuration

import { saveConfig } from '@sailboat-computer/config-loader';

// Save configuration
await saveConfig<MyConfig>(
  'my-service/config.json',
  config,
  'Updated database settings', // Optional description
  'admin' // Optional user
);

Configuration Versioning

import { 
  saveConfig, 
  getConfigVersions, 
  getConfigVersion, 
  rollbackConfig 
} from '@sailboat-computer/config-loader';

// Save configuration with description
await saveConfig<MyConfig>(
  'my-service/config.json',
  config,
  'Updated database settings'
);

// Get all versions
const versions = await getConfigVersions('my-service/config.json');
console.log(`Available versions: ${versions.length}`);

// Get a specific version
const version = await getConfigVersion<MyConfig>('my-service/config.json', 1);
console.log(`Version 1 created at: ${version?.metadata.timestamp}`);

// Rollback to a previous version
const rolledBackConfig = await rollbackConfig<MyConfig>(
  'my-service/config.json',
  1,
  'Rollback to initial configuration'
);

API

loadConfig<T>(path: string, defaultConfig?: T, options?: ConfigLoaderOptions): Promise<T>

Loads configuration from a file.

  • path: Path to the configuration file (relative to baseDir)
  • defaultConfig: Default configuration to use if the file doesn't exist or to merge with
  • options: Configuration loader options

saveConfig<T>(path: string, config: T, description?: string, user?: string, options?: ConfigLoaderOptions): Promise<void>

Saves configuration to a file.

  • path: Path to the configuration file (relative to baseDir)
  • config: Configuration to save
  • description: Optional description of the change
  • user: Optional user who made the change
  • options: Configuration loader options

getConfigVersions(path: string, options?: ConfigLoaderOptions): Promise<ConfigVersionMetadata[]>

Gets all available versions for a configuration file.

  • path: Path to the configuration file (relative to baseDir)
  • options: Configuration loader options
  • Returns: List of version metadata

getConfigVersion<T>(path: string, version: number, options?: ConfigLoaderOptions): Promise<ConfigVersion<T> | null>

Gets a specific version of a configuration file.

  • path: Path to the configuration file (relative to baseDir)
  • version: Version number
  • options: Configuration loader options
  • Returns: Configuration version or null if not found

rollbackConfig<T>(path: string, version: number, description?: string, user?: string, options?: ConfigLoaderOptions): Promise<T>

Rolls back to a specific version of a configuration file.

  • path: Path to the configuration file (relative to baseDir)
  • version: Version number
  • description: Optional description of the rollback
  • user: Optional user who performed the rollback
  • options: Configuration loader options
  • Returns: The rolled back configuration

createConfigLoader(options?: ConfigLoaderOptions): ConfigLoader

Creates a configuration loader.

  • options: Configuration loader options

ConfigLoaderOptions

Options for the configuration loader:

  • baseDir: Base directory for configuration files (default: 'config')
  • envPrefix: Environment variable prefix for configuration overrides (default: 'CONFIG_')
  • validate: Whether to validate configuration against schema (default: true)
  • watch: Whether to watch for configuration changes (default: false)
  • required: Whether to throw an error if configuration file is not found (default: false)
  • mergeDefaults: Whether to merge with default values (default: true)
  • logger: Custom logger

License

MIT