checkoutOs
Guides

Configuration

Every environment variable, how validation works, and the one variable that bypasses it.

src/config/env.schema.ts validates the environment with Zod at module load time. Invalid config calls process.exit(1) — the process never starts with a broken configuration.

Core variables

VariableRequiredDefaultDescription
NODE_ENVNodevelopmentdevelopment / production / test
PORTNo3000HTTP server port (1024–65535)
ACTIVE_GATEWAYYes—razorpay / paytm / payu / cashfree
REDIS_URLYes—Redis connection string (redis:// or rediss://)
WEBHOOK_RELAY_URLYes—Where normalized webhooks are relayed
BASE_URLNohttp://localhost:3000Public origin used to build paymentUrl

BASE_URL is not Zod-validated

It is read directly via process.env.BASE_URL in config/index.ts and defaults to http://localhost:3000. If you forget it in production, every paymentUrl you hand a customer points at localhost — and nothing will warn you, because validation never sees it.

Observability variables

All optional.

VariableDefaultDescription
APP_VERSION0.0.0Stamped on logs and the OTel resource
LOG_FORMATTTY-dependentjson or pretty
METRICS_PORT9464/metrics listener; must differ from PORT
METRICS_AUTH_TOKENunsetBearer token required by /metrics when set
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTunsetEnables OTLP trace export
TRACE_SAMPLE_RATIO0.1Share of non-failed traces kept (0–1)

Gateway credentials

A Zod superRefine makes the active gateway's credentials required. Credentials for inactive gateways are ignored.

RAZORPAY_KEY_ID=rzp_live_xxxxxxxxxxxx
RAZORPAY_KEY_SECRET=xxxxxxxxxxxxxxxxxxxxxxxx
RAZORPAY_WEBHOOK_SECRET=xxxxxxxxxxxxxxxx
RAZORPAY_BASE_URL=            # optional override

The config object

Validated env is grouped rather than read ad hoc:

config.gateway.active        // 'razorpay'
config.gateway.credentials   // Record<string, string>
config.redis.url
config.webhook.relayUrl
config.app.baseUrl
config.metrics.port

Read from config, never from process.env, outside config/. The registry is stricter still: it receives the validated env as a parameter and never imports config/index.ts, to avoid a circular dependency.

Startup sequence

src/server.ts
  → src/bootstrap.ts    dotenv + configureLogger + verifyTelemetry
  → src/app.ts
      initialise()      registerGateways() → connectRedis()   (failure exits)
      buildApp()        pure factory, no side effects

buildApp() having no side effects is what makes it safe to call in tests without a Redis connection or a registered gateway.

On this page