Configuration

Typed Config

Validate and type environment variables at startup.

1 min readDocumentationEdit this page

Usage#

typescript
import { loadEnv, defineConfig } from '@AxilJS/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().

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY