API Reference

c12

Layered configuration loader for Node.js, merging defaults, config files, environment, and overrides with watch support.

Official Documentation ↗
CompatibilityThis documentation covers version v2.0. Check the official docs for the latest API surface.

Installation

npmnpm install c12

Methods

c12 is layered configuration loader for node.js, merging defaults, config files, environment, and overrides with watch support. This page documents the core methods, installation, and common usage patterns for the current stable release.

Installation

Install c12 with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.

Core methods

The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v2.0 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.

Frequently asked questions

The faq section in the frontmatter answers the most common questions about c12, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.

API reference evidence

Fetched from official sources on 2026-11-08T19:25:00+08:00 via WebFetch https://raw.githubusercontent.com/unjs/c12/main/README.md;WebFetch https://raw.githubusercontent.com/unjs/c12/main/src/loader.ts;WebFetch https://raw.githubusercontent.com/unjs/c12/main/src/watch.ts.

  • loadConfig → signature from https://raw.githubusercontent.com/unjs/c12/main/src/loader.ts; official text: “export async function loadConfig< T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta, >(options: LoadConfigOptions<T, MT>): Promise<ResolvedConfig<T, MT>> {”
  • watchConfig → signature from https://raw.githubusercontent.com/unjs/c12/main/src/watch.ts; official text: “export async function watchConfig< T extends UserInputConfig = UserInputConfig, MT extends ConfigLayerMeta = ConfigLayerMeta, >(options: WatchConfigOptions<T, MT>): Promise<ConfigWatcher<T, MT>> {”

FAQ

Which file formats are supported?
JSON, JSON5, YAML, TOML, JS, and MJS via jiti; the loader tries each extension.
How does layering work?
It deep-merges defaults, file config, environment overrides, and a programmatic override in order.
Can I use it with dotenv?
Yes. c12 reads .env files automatically; set dotenv: true in options.