@nestjs/config loads your .env file and makes every variable available throughout the application.
Sample .env file
.env
Variable reference
Database
PostgreSQL connection string used by both Drizzle ORM (migrations, seeds) and the runtime connection pool.Format: The
postgresql://<user>:<password>@<host>:<port>/<database>drizzle.config.ts reads this variable directly and throws an error at startup if it is not set:DrizzleModule also validates this variable on application bootstrap — the API will not start without it.Server
The port the NestJS HTTP server listens on.
Defaults to
3000 when not set. On Railway and other PaaS platforms, the platform injects PORT automatically.Authentication
Secret key used to sign and verify JWT access tokens. Use a long, randomly generated string.If this variable is not set, the application falls back to the insecure default value
default-secret. Always set an explicit secret in production.How long a JWT access token remains valid. Accepts any value supported by the
jsonwebtoken library.Examples: 15m, 1h, 24h, 7d.Defaults to
24h when not set.How variables are loaded
app.module.ts registers ConfigModule globally:
ConfigService and call configService.get<string>('VARIABLE_NAME') without importing ConfigModule again. The module reads from the .env file in the project root by default.
Docker Compose
When running with Docker Compose, pass environment variables through your.env file. Docker Compose automatically reads .env from the project root and makes the values available to the containers.
The
.dockerignore file excludes .env, .env.local, and .env.*.local from the Docker build context. Environment variables are injected at runtime — they are never baked into the image.