Typed Config
Validate and type environment variables at startup.
1 min readEdit this page
Usage
import { loadEnv, defineConfig } from '@restjs/config'
loadEnv()
const config = defineConfig({
PORT: { type: 'number', default: 3000 },
DATABASE_URL: { type: 'string', required: true },
DEBUG: { type: 'boolean', default: false },
NODE_ENV: { type: 'string', enum: ['development', 'production', 'test'] },
RATE_LIMIT: { type: 'number', default: 100, min: 1, max: 1000 }
})If required fields are missing, the app fails at startup with clear errors.
Tip
Always call loadEnv() before defineConfig().