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

@synet/config

v1.0.0

Published

Simple, immutable configuration management from multiple sources, supporting environment variables, JSON files, and more. Designed with Unit Architecture.

Readme

@synet/config

   _____             __ _         _    _       _ _   
  / ____|           / _(_)       | |  | |     (_) |  
 | |     ___  _ __ | |_ _  __ _  | |  | |_ __  _| |_ 
 | |    / _ \| '_ \|  _| |/ _` | | |  | | '_ \| | __|
 | |___| (_) | | | | | | | (_| | | |__| | | | | | |_ 
  \_____\___/|_| |_|_| |_|\__, |  \____/|_| |_|_|\__|
                           __/ |                     
                          |___/                      
version: 1.0.0

Simple, immutable configuration management for Node.js applications.

Installation

npm install @synet/config

Quick Start

import { Config } from '@synet/config';

// Load from environment variables
const config = Config.fromEnv();
console.log(config.get('NODE_ENV', 'development'));

// Load from JSON
const jsonConfig = Config.fromJSON('{"port": 3000, "debug": true}');
console.log(jsonConfig.get('port')); // 3000

// Merge configurations
const merged = config.merge(jsonConfig);

Features

  • Immutable - All operations return new instances
  • Type-safe - Full TypeScript support with generics
  • Multi-source - Environment variables, JSON, and objects
  • Zero dependencies - Lightweight and secure
  • Chainable - Fluent API for configuration composition

API Reference

Static Methods

Config.create(options?)

Create a config instance with optional initial data.

const config = Config.create({
  name: 'AppConfig',
  data: { debug: true, port: 3000 }
});

Config.fromEnv(prefix?)

Load configuration from environment variables.

// Load all environment variables
const envConfig = Config.fromEnv();

// Load only variables with specific prefix
const appConfig = Config.fromEnv('APP_');
// APP_NAME=myapp becomes { name: 'myapp' }

Config.fromJSON(jsonString)

Parse JSON string into configuration.

const config = Config.fromJSON(`{
  "database": {"host": "localhost", "port": 5432},
  "cache": {"ttl": 3600}
}`);

Config.fromObject(object, name?)

Create configuration from object.

const config = Config.fromObject({
  debug: true,
  features: ['auth', 'logging']
}, 'MyConfig');

Instance Methods

get<T>(key, defaultValue?): T

Retrieve configuration value with optional default.

const port = config.get<number>('port', 3000);
const debug = config.get<boolean>('debug', false);

has(key): boolean

Check if configuration key exists.

if (config.has('database')) {
  // Database configuration is available
}

getAll(): Record<string, unknown>

Get all configuration data as an object.

const allConfig = config.getAll();
console.log(JSON.stringify(allConfig, null, 2));

keys(): string[]

Get array of all configuration keys.

const configKeys = config.keys();
console.log('Available settings:', configKeys);

merge(other): Config

Create new configuration by merging with another config.

const envConfig = Config.fromEnv();
const fileConfig = Config.fromJSON(jsonString);
const merged = envConfig.merge(fileConfig);
// Later values override earlier ones

toJSON(): object

Export configuration data and metadata.

const exported = config.toJSON();
// Includes: unitId, version, name, data, source, created

Properties

  • name: string - Configuration name
  • size: number - Number of configuration keys
  • source: 'env' | 'json' | 'object' - Configuration source type

Common Patterns

Environment-based Configuration

// Load environment-specific config
const config = Config.fromEnv()
  .merge(Config.fromJSON(fs.readFileSync(`config/${process.env.NODE_ENV}.json`, 'utf8')));

const dbUrl = config.get('DATABASE_URL');
const port = config.get<number>('PORT', 3000);

Layered Configuration

// Base config
const defaults = Config.fromObject({
  timeout: 5000,
  retries: 3,
  debug: false
});

// Environment overrides
const envConfig = Config.fromEnv('APP_');

// Runtime overrides
const runtime = Config.fromObject({
  timestamp: Date.now()
});

// Final configuration
const config = defaults.merge(envConfig).merge(runtime);

Configuration Validation

const config = Config.fromEnv();

// Type-safe access with defaults
const port = config.get<number>('PORT', 3000);
const host = config.get<string>('HOST', 'localhost');

// Existence checks
if (!config.has('DATABASE_URL')) {
  throw new Error('DATABASE_URL is required');
}

TypeScript Support

Full TypeScript support with generic type inference:

interface AppConfig {
  port: number;
  host: string;
  debug: boolean;
  features: string[];
}

const config = Config.fromJSON(jsonString);

const port = config.get<number>('port', 3000);     // number
const host = config.get<string>('host');           // string | undefined  
const debug = config.get<boolean>('debug', false); // boolean
const features = config.get<string[]>('features'); // string[] | undefined

Error Handling

The library throws clear, actionable errors:

try {
  const config = Config.fromJSON('invalid json');
} catch (error) {
  console.error(error.message); // "[config] Invalid JSON: ..."
}

Performance

  • Lightweight - Zero external dependencies
  • Fast - Simple object operations, no complex parsing
  • Memory efficient - Immutable operations reuse data where possible

License

MIT