@entergreat/config
v1.0.0
Published
Environment variable validation with type coercion - fail fast on missing required vars
Downloads
206
Readme
@entergreat/config
Environment variable validation with type coercion. Fail fast on missing required vars. Used by all EnterGreat services.
Installation
npm install @entergreat/configUsage
import { loadConfig } from '@entergreat/config';
const config = loadConfig({
required: ['DATABASE_URL', 'ANTHROPIC_API_KEY'],
optional: {
PORT: { type: 'number', default: 3000 },
DEBUG: { type: 'boolean', default: false },
LOG_LEVEL: { type: 'string', default: 'info' },
},
});
// config.DATABASE_URL → string (guaranteed present)
// config.PORT → number (coerced from env or default)
// config.DEBUG → boolean (coerced from "true"/"false")API
loadConfig({ required, optional })
Loads .env file (or ENV_FILE path), validates required vars, coerces optional vars.
Throws if any required variable is missing:
Error: Missing required env vars: DATABASE_URL, ANTHROPIC_API_KEYParameters
| Field | Type | Description |
|-------|------|-------------|
| required | string[] | Env vars that must be present. Throws on missing. |
| optional | object | Env vars with type coercion and defaults. |
Optional Spec
| Property | Values | Description |
|----------|--------|-------------|
| type | "string", "number", "boolean" | Coercion type |
| default | any | Fallback when env var is not set |
Env File
Reads .env by default. Override with ENV_FILE environment variable:
ENV_FILE=.env.production node app.jsDependencies
| Package | Purpose |
|---------|---------|
| dotenv | .env file loading |
