Introduction
viper is a minimal, Viper-inspired configuration management library for TypeScript. It draws inspiration from Go's spf13/viper and brings the same layered configuration model to the TypeScript ecosystem.
Why viper?
Managing application configuration often involves juggling multiple sources: config files, environment variables, defaults, and runtime overrides. viper unifies them into a single registry with clear precedence rules.
Core Concepts
- Layered sources — defaults, config file, environment variables, and explicit overrides are merged with well-defined priority
- Dot-notation keys — access nested config via
database.hostinstead ofconfig.database.host - Case-insensitive —
DATABASE.HOST,database.host, andDatabase.Hostall resolve to the same key - JSON5 config files — comments, trailing commas, and unquoted keys in your config files
- Zod validation — optional schema validation at read and write time
- Atomic writes — config file writes use temp file + rename for crash safety
Precedence Order
When you read a key, viper checks sources in this order (first match wins):
- Override —
v.set(key, value) - Environment variable — bound or automatic env lookup
- Config file — parsed JSON5 file
- Default —
v.setDefault(key, value)
Next Steps
- Getting Started — install and write your first config
- Guides — learn how each feature works
- API Reference — full method documentation