Documentation

Configuration

Configure the application, database, authentication, mail, limits, logging, and bootstrap administrator.

Edit on GitHub

Configuration

Configuration is loaded through NestJS ConfigModule and validated before the application starts. Development uses .env; tests prefer .env.test and fall back to .env. Production ignores environment files and reads process environment variables.

Copy the example for local development:

plaintext
cp .env.example .env

Application and HTTP

VariableRequired or defaultDescription
NODE_ENVdevelopmentOne of development, test, or production
APP_NAMEnestjs-modular-monolith-starter-kitService name used by OpenAPI, logging, and PostgreSQL connection metadata
APP_HOST0.0.0.0Interface used by the HTTP listener
APP_PORT3000HTTP listener port
APP_GLOBAL_PREFIXapiPrefix for versioned API routes
API_PUBLIC_URLhttp://localhost:3000/apiPublic API URL used to construct Problem Details identifiers
APP_TRUST_PROXY_HOPS1Number of trusted reverse-proxy hops
CORS_ORIGINShttp://localhost:3001Comma-separated browser origins allowed by CORS
OPENAPI_ENABLEDfalseRegisters /docs and /openapi.json when enabled
WEB_APP_URLhttp://localhost:3001Frontend URL used by email-verification links

The application accepts Content-Type, Authorization, X-Request-Id, and X-CSRF-Token request headers. CORS credentials are enabled.

Database

VariableRequired or defaultDescription
POSTGRES_PORT5433 in ComposeHost port published by the PostgreSQL container; not consumed by the API directly
DATABASE_URLRequiredFull postgres:// or postgresql:// connection URL
DATABASE_SSLfalseEnables TLS with certificate verification
DATABASE_POOL_SIZE10Maximum TypeORM/PostgreSQL pool size, from 1 to 100

For the included Compose service:

plaintext
POSTGRES_PORT=5433
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/nestjs
DATABASE_SSL=false
DATABASE_POOL_SIZE=10

JWT and cookies

VariableRequired or defaultDescription
JWT_ACCESS_SECRETRequired, minimum 32 charactersSigns access tokens
JWT_ACCESS_TTL15mAccess-token lifetime using an integer plus s, m, h, or d
JWT_REFRESH_SECRETRequired, minimum 32 charactersSigns refresh tokens; use a different value from the access secret
JWT_REFRESH_TTL30dRefresh-token and session lifetime, capped at 30 days
JWT_ISSUERyour-jwt-issuerExpected JWT issuer
JWT_AUDIENCEyour-jwt-audienceExpected JWT audience
AUTH_REFRESH_COOKIE_NAMEyour-auth-refresh-cookie-nameHTTP-only refresh-token cookie name
AUTH_CSRF_COOKIE_NAMEyour-auth-cookie-nameCSRF cookie name
AUTH_COOKIE_SECUREfalseSends authentication cookies only over HTTPS
AUTH_COOKIE_SAME_SITElaxCookie policy: strict, lax, or none

Production requires AUTH_COOKIE_SECURE=true. SameSite=None also requires secure cookies.

Passwords and verification

VariableRequired or defaultDescription
ARGON2_MEMORY_KIB65536Argon2 memory usage in KiB; minimum 19456
ARGON2_TIME_COST3Argon2 iteration cost; minimum 2
ARGON2_PARALLELISM1Argon2 parallelism, from 1 to 16
EMAIL_VERIFICATION_TTL_MINUTES1440Email-verification token lifetime

Increasing Argon2 costs increases password-hashing resource use. Measure the effect on the target runtime before changing production values.

Rate limits and uploads

VariableRequired or defaultDescription
THROTTLE_TTL_MS60000Global rate-limit window in milliseconds
THROTTLE_LIMIT100Maximum requests per global window
UPLOAD_MAX_BYTES10485760Maximum configured upload size in bytes

Authentication endpoints may define stricter per-route limits in addition to the global limit.

Mail

VariableRequired or defaultDescription
MAIL_HOSTRequiredSMTP host
MAIL_PORT587SMTP port
MAIL_SECUREfalseUses a secure SMTP connection
MAIL_USEREmptySMTP username; an empty value disables authentication
MAIL_PASSWORDEmptySMTP password
MAIL_FROMRequiredDefault sender address

Mailpit development values:

plaintext
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_SECURE=false
MAIL_USER=
MAIL_PASSWORD=
MAIL_FROM=no-reply@localhost

Bootstrap administrator

VariableRequired or defaultDescription
BOOTSTRAP_ADMIN_EMAILEmptyAdministrator email used by pnpm seed:admin
BOOTSTRAP_ADMIN_PASSWORDEmptyAdministrator password used by the seed
BOOTSTRAP_ADMIN_DISPLAY_NAMEEmptyAdministrator display name used by the seed

Do not set these in production unless the bootstrap command is intentionally being run. Do not commit real credentials.

Logging

VariableRequired or defaultDescription
LOG_LEVELinfoOne of error, warn, info, http, verbose, debug, or silly

Development console output is human-readable. Production console output and file transports use structured JSON. Tests do not create file transports.

Production validation

The process refuses to start when:

  • API_PUBLIC_URL contains credentials, a query, or a fragment.
  • NODE_ENV=production and API_PUBLIC_URL is not HTTPS.
  • NODE_ENV=production and AUTH_COOKIE_SECURE is false.
  • AUTH_COOKIE_SAME_SITE=none and AUTH_COOKIE_SECURE is false.
  • A required value is missing or violates its schema.

A minimal production-oriented excerpt:

plaintext
NODE_ENV=production
APP_HOST=0.0.0.0
APP_PORT=3000
API_PUBLIC_URL=https://api.example.com/api
WEB_APP_URL=https://app.example.com
AUTH_COOKIE_SECURE=true
AUTH_COOKIE_SAME_SITE=lax
DATABASE_SSL=true
OPENAPI_ENABLED=false
LOG_LEVEL=info

Supply secrets and service credentials through the deployment platform rather than a committed environment file.

On this page