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

mikroconf

v1.0.0

Published

A flexible, zero-dependency, type-safe configuration manager that just makes sense.

Readme

MikroConf

A flexible, zero-dependency, type-safe configuration manager that just makes sense.

npm version

bundle size

Build Status

License: MIT


  • Load configuration from multiple sources (defaults, files, environment, CLI)
  • Strong TypeScript support with typed configuration access
  • Nested configuration with dot notation path support
  • Built-in parsers and validators
  • Simple API
  • Tiny (~1.3kb gzipped)
  • Zero dependencies

Installation

npm install mikroconf -S

Usage

Quick Start

Let's look at a simple example where we use a configuration file to retrieve values. Values that are not provided are picked from the defaults.

import { MikroConf } from 'mikroconf';

/*
// config.json
{
  "server": {
    "host: "http://1.2.3.4",
    "port": 8080
  }
}
*/

const config = new MikroConf({
  configFilePath: 'config.json', // Load from this file if it exists
  options: [
    { path: 'server.host', defaultValue: 'localhost' }, // Will use the provided value
    { path: 'server.port', defaultValue: 3000 }, // Will use the provided value
    { path: 'logging.level', defaultValue: 'info' }, // Will use the default value
    { path: 'debug', defaultValue: process.env.DEBUG === 'true' ? true : false } // Will use the default value
  ]
});

// Get the entire configuration
const appConfig = config.get();
console.log(appConfig);

// Get specific values
const port = config.getValue('server.port');
const host = config.getValue('server.host');
console.log(`Server will start at http://${host}:${port}`);

Validation

You can add validators to ensure your configuration meets your requirements:

import { MikroConf, validators } from 'mikroconf';

const config = new MikroConf({
  // ...
  validators: [
    {
      path: 'database.url',
      validator: (url) => {
        if (!url) return 'Database URL is required';
        return true;
      },
      message: 'Invalid database configuration'
    }
  ]
});

try {
  const appConfig = config.get(); // Validates automatically
  // Start application
  // ...
} catch (error) {
  console.error(`Configuration error: ${error.message}`);
  process.exit(1);
}

Working with CLI Arguments

MikroConf automatically maps CLI arguments to your configuration structure:

import { MikroConf, parsers, validators } from 'mikroconf';

const config = new MikroConf({
  args: process.argv, // Pass in CLI arguments (typically process.argv)
  options: [
    {
      flag: '--port', // The CLI flag or parameter
      path: 'server.port',
      defaultValue: 3000,
      parser: parsers.int, // Convert string to integer
      validator: validators.range(1024, 65535) // Validate the value
    },
    { flag: '--tags', path: 'tags', parser: parsers.array }, // Array
    { flag: '--debug', path: 'debug', isFlag: true } // Boolean flag
  ]
});

// Example: node app.js --port 8080 --debug --tags api,auth,v1
console.log(config.getValue('server.port')); // 8080 (number)
console.log(config.getValue('debug')); // true (boolean)
console.log(config.getValue('tags')); // ['api', 'auth', 'v1'] (array)

And a more elaborate example:

import { MikroConf, parsers, validators } from 'mikroconf';

/*
// app-config.json
{
  "server": {
    "port": 1234
  },
  "logging": {
    "level": "DEBUG"
  },
  "database": {
    "url": "postgres://my-db"
  }
}
*/

// Load values from a file and validate them
const config = new MikroConf({
  configFilePath: 'app-config.json',
  options: [
    {
      flag: '--port',
      path: 'server.port',
      defaultValue: 3000,
      parser: parsers.int,
      validator: validators.range(1024, 65535)
    },
    {
      flag: '--log-level',
      path: 'logging.level',
      defaultValue: 'info',
      validator: validators.oneOf(['debug', 'info', 'warn', 'error'])
    }
  ],
  validators: [
    {
      path: 'database.url',
      validator: (url) => {
        if (!url) return 'Database URL is required';
        if (typeof url !== 'string') return 'Database URL must be a string';
        if (!url.startsWith('mongodb://') && !url.startsWith('postgres://')) {
          return 'Database URL must start with mongodb:// or postgres://';
        }
        return true;
      },
      message: 'Invalid database configuration'
    }
  ]
});

try {
  const appConfig = config.get();
  console.log(appConfig);
  console.log('Configuration validated successfully');
} catch (error) {
  console.error(`Configuration error: ${error.message}`);
  process.exit(1);
}

Type Safety

Get full TypeScript type checking with your configuration:

import { MikroConf, parsers } from 'mikroconf';

// Define your configuration type
interface AppConfig {
  server: {
    port: number;
    host: string;
  };
  database: {
    url: string;
    maxConnections: number;
  };
  features: {
    enableAuth: boolean;
    enableCache: boolean;
  };
}

const config = new MikroConf({
  configFilePath: 'app-config.json',
  options: [
    { flag: '--port', path: 'server.port', defaultValue: 3000, parser: parsers.int },
    { flag: '--db-url', path: 'database.url' },
    { flag: '--enable-auth', path: 'features.enableAuth', isFlag: true }
  ]
});

// Get typed configuration
const appConfig = config.get<AppConfig>();
console.log('appConfig', appConfig);

// TypeScript knows the types of these properties
const serverPort: number = appConfig.server.port;
const dbUrl: string = appConfig.database.url;
const authEnabled: boolean = appConfig.features.enableAuth;

console.log(serverPort, dbUrl, authEnabled);

Configuration Sources (in order of precedence)

  1. Command line arguments (highest priority)
  2. Programmatically provided config
  3. Config file (JSON)
  4. Default values (lowest priority)

License

MIT. See the LICENSE file.