Skip to content

Environment Variables

Environment variables configure VeloxTS applications at runtime.

VariableDescriptionExample
NODE_ENVEnvironment modedevelopment, production
PORTServer port3030
VariableDescriptionExample
DATABASE_URLDatabase connection stringpostgresql://user:pass@host:5432/db
VariableDescriptionMinimum
JWT_SECRETAccess token signing key32 characters
JWT_REFRESH_SECRETRefresh token signing key32 characters
SESSION_SECRETSession signing key32 chars, 16 unique
VariableDescriptionDefault
HOSTServer bind address0.0.0.0
LOG_LEVELLogging verbosityinfo
CORS_ORIGINSAllowed origins (comma-separated)*
VariableDescriptionDefault
REDIS_URLRedis connection URL-
CACHE_PREFIXKey prefixapp:
CACHE_TTLDefault TTL (seconds)3600
VariableDescriptionDefault
MAIL_DRIVERMail driversmtp
SMTP_HOSTSMTP server host-
SMTP_PORTSMTP server port587
SMTP_USERSMTP username-
SMTP_PASSSMTP password-
RESEND_API_KEYResend API key-
MAIL_FROMDefault from address-
VariableDescriptionDefault
STORAGE_DRIVERStorage driverlocal
STORAGE_PATHLocal storage path./uploads
S3_BUCKETS3 bucket name-
S3_REGIONAWS region-
AWS_ACCESS_KEY_IDAWS access key-
AWS_SECRET_ACCESS_KEYAWS secret key-
.env
NODE_ENV=development
PORT=3030
# Database (SQLite for dev)
DATABASE_URL=file:./dev.db
# Auth (use secure values in production!)
JWT_SECRET=dev-jwt-secret-min-32-characters-long
JWT_REFRESH_SECRET=dev-refresh-secret-min-32-chars-here
# Optional: Enable pretty logging
LOG_LEVEL=debug
.env.production
NODE_ENV=production
PORT=3030
# Database (PostgreSQL)
DATABASE_URL=postgresql://user:password@host:5432/myapp?sslmode=require
# Auth (generate secure secrets!)
JWT_SECRET=your-production-jwt-secret-min-32-chars
JWT_REFRESH_SECRET=your-production-refresh-secret-32-chars
# Redis (for cache, queue, sessions)
REDIS_URL=redis://user:password@host:6379
# Mail
MAIL_DRIVER=resend
RESEND_API_KEY=re_xxxxxxxxxxxxx
MAIL_FROM=noreply@yourdomain.com
# Storage
STORAGE_DRIVER=s3
S3_BUCKET=your-bucket
S3_REGION=us-east-1
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=...
# Security
CORS_ORIGINS=https://yourdomain.com,https://app.yourdomain.com
LOG_LEVEL=warn
Terminal window
# Generate a secure random secret (Node.js)
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
# Generate using OpenSSL
openssl rand -base64 32

VeloxTS uses dotenv for environment variable loading:

// Automatic loading in entry point
import 'dotenv/config';
// Or manual loading
import dotenv from 'dotenv';
dotenv.config({ path: '.env.production' });

For RSC apps with Vite, load dotenv explicitly:

import dotenv from 'dotenv';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
dotenv.config({ path: resolve(__dirname, '..', '.env') });

Validate required environment variables at startup:

import { z } from 'zod';
const envSchema = z.object({
NODE_ENV: z.enum(['development', 'production', 'test']),
DATABASE_URL: z.string().min(1),
JWT_SECRET: z.string().min(32),
JWT_REFRESH_SECRET: z.string().min(32),
});
const env = envSchema.parse(process.env);