@forgekit/config
@forgekit/config enforces strict environment variables schema validation at runtime initialization, preventing app boot processes if configurations are invalid.
Environment Variable Schema Definition
Define and parse variables using a lightweight type-safe schema:
import { ForgeApp } from '@forgekit/core';
import { config, z } from '@forgekit/config';
const app = new ForgeApp();
app.use(
config({
schema: {
PORT: z.number().default(3000),
DATABASE_URL: z.string().url(),
NODE_ENV: z.enum(['development', 'production', 'test'])
}
})
);
// Properties are fully typed on the config object
const port = app.config.PORT; // Checked as number
const env = app.config.NODE_ENV; // Typed as 'development' | 'production' | 'test' Validation Failure Reports
If validation fails on startup (e.g. DATABASE_URL is missing or is not a valid URL format), ForgeKit throws a detailed validation report and terminates gracefully:
[FORGEKIT CONFIG ERROR]: Schema validation failed on startup
- DATABASE_URL: Expected string matching url format, received undefined
- NODE_ENV: Expected 'development' | 'production', received 'staging'