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
| Variable | Required | Default | Description |
|---|---|---|---|
NODE_ENV | No | development | development / production / test |
PORT | No | 3000 | HTTP server port (1024–65535) |
ACTIVE_GATEWAY | Yes | — | razorpay / paytm / payu / cashfree |
REDIS_URL | Yes | — | Redis connection string (redis:// or rediss://) |
WEBHOOK_RELAY_URL | Yes | — | Where normalized webhooks are relayed |
BASE_URL | No | http://localhost:3000 | Public 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.
| Variable | Default | Description |
|---|---|---|
APP_VERSION | 0.0.0 | Stamped on logs and the OTel resource |
LOG_FORMAT | TTY-dependent | json or pretty |
METRICS_PORT | 9464 | /metrics listener; must differ from PORT |
METRICS_AUTH_TOKEN | unset | Bearer token required by /metrics when set |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | unset | Enables OTLP trace export |
TRACE_SAMPLE_RATIO | 0.1 | Share 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 overrideThe 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.portRead 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 effectsbuildApp() having no side effects is what makes it safe to call in tests without a Redis
connection or a registered gateway.