Skip to content

Environment Variables ​

ZViewer is configured through environment variables. You can set them in a .env file (copy from .env.example) or via system environment variables.


Backend Environment Variables ​

Basic Configuration ​

VariableDescriptionDefaultExample
PORTBackend service port3333PORT=3333
HOSTListen addressEmpty (dual-stack)HOST=0.0.0.0
NODE_ENVRuntime environmentproductionNODE_ENV=development

Storage Paths ​

When all paths are left empty, the defaults under <project-root>/config/ are used.

VariableDescriptionDefault
CONFIG_DIRData root directory<project-root>/config
DATABASE_URLDatabase connection<config>/dev.sqlite
UPLOADS_DIRUploaded files directory<config>/uploads
AVATARS_DIRAvatars directory<config>/avatars
MEDIA_DIRNMS streaming temporary directory<config>/media

PostgreSQL example: DATABASE_URL=postgresql://user:password@localhost:5432/zviewer (requires synchronizing changes in data-source.ts)

CORS Configuration ​

VariableDescriptionDefault
CORS_ORIGINAllowed CORS origins, comma-separated*

For production, it is recommended to set this to the specific frontend domain, e.g., CORS_ORIGIN=https://example.com.

JWT Authentication (must change in production) ​

VariableDescriptionDefaultRecommendation
JWT_ACCESS_SECRETAccess Token secretAuto-generated32+ character random string
JWT_REFRESH_SECRETRefresh Token secretAuto-generated32+ character random string, different from the above
JWT_ACCESS_EXPIRES_INAccess Token validity15m15m or 30m
JWT_REFRESH_EXPIRES_INRefresh Token validity7d7d or 14d

Streaming Ports ​

VariableDescriptionDefault
RTMP_PORTRTMP streaming port3334
HTTP_FLV_PORTHTTP-FLV pull stream port3335

Additional Variables ​

VariableDescriptionExample
HTTPSEnable HTTPS modeHTTPS=true
SSL_CERT_PATHCertificate pathconfig/ssl/cert.pem
SSL_KEY_PATHPrivate key pathconfig/ssl/key.pem
SERVER_HOSTHostname preferred for RTMP addressSERVER_HOST=example.com

Frontend Build Environment Variables ​

Used when building the frontend, not at runtime.

VariableDescriptionDefault
VITE_API_URLAPI/Socket.IO base URLEmpty (uses window.location.origin)
VITE_FLV_BASE_URLHTTP-FLV pull stream base URLEmpty (uses same-origin address)

Configuration Examples ​

Minimal Configuration (Development) ​

ini
PORT=3333
NODE_ENV=development
ini
PORT=3333
NODE_ENV=production
CORS_ORIGIN=https://your-frontend-domain.com
JWT_ACCESS_SECRET=<32+ character random string>
JWT_REFRESH_SECRET=<another 32+ character random string>
JWT_ACCESS_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d

Generating Random Keys ​

bash
# Linux / macOS
openssl rand -base64 32

# or Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

This project is licensed under CC BY-NC-SA.