@extasyio/core-config
v0.2.0
Published
Configuration loader & validator using Zod schemas
Readme
@extasyio/core-config
Enhanced configuration loader & validator using Zod schemas.
Features
- .env support: automatic loading of
.envfiles viadotenv. - Schema merge: combine multiple Zod schemas with
mergeConfig(). - Hot-reload: watch
.envand reload config in runtime viawatchConfig(). - CLI: scaffold a config template with
core-config init [output].
Usage
import { z } from 'zod';
import { loadConfig, mergeConfig, watchConfig } from '@extasyio/core-config';
// Single schema
const Schema = z.object({ PORT: z.coerce.number().default(3000) });
const cfg = loadConfig(Schema);
// Merge multiple schemas
const Other = z.object({ HOST: z.string().default('localhost') });
const fullCfg = mergeConfig([Schema, Other]);
// Watch for changes
watchConfig(Schema, {}, updated => {
console.log('New config:', updated);
});