Skip to main content

Overview

DefDrive uses environment variables for configuration. Create a .env file in the root directory based on .env.example.

Required Variables

These variables must be set for DefDrive to run:

DATABASE_URL

Type: String (PostgreSQL connection URL)
Required: Yes
Used in: main.go:25
PostgreSQL database connection URL in the format:
DATABASE_URL=postgres://username:password@host:port/database
The application will fail to start if DATABASE_URL is not set. Ensure your PostgreSQL instance is accessible at the specified URL.
Example:
DATABASE_URL=postgres://defdrive_user:secure_password@localhost:5432/defdrive
Docker Compose Example:
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}

JWT_SECRET

Type: String
Required: Yes
Used in: middleware/auth.go:40, controllers/user.go:83
Secret key used for signing and verifying JWT authentication tokens.
JWT_SECRET=your_secret_key_here
Use a strong, randomly generated secret in production. Never commit this value to version control.
Generate a secure secret:
openssl rand -base64 32

Server Configuration

PORT

Type: Integer
Required: No
Default: 8080
Used in: main.go:73
Port number on which the DefDrive server will listen.
PORT=5050
Example:
PORT=3000  # Run on port 3000

HOST_URL

Type: String (URL)
Required: Yes (for link generation)
Used in: controllers/access.go:106
Base URL of your DefDrive instance, used for generating shareable file access links.
HOST_URL=http://localhost:5050
Production Example:
HOST_URL=https://drive.yourdomain.com
This URL is prepended to generated access links. Ensure it matches your actual deployment URL, including protocol (http/https) and port if non-standard.

Storage Configuration

DATA_PATH

Type: String (Directory path)
Required: No
Default: ./data
Directory path where uploaded files will be stored.
DATA_PATH=./data
Production Example:
DATA_PATH=/var/lib/defdrive/data
Ensure this directory exists and has proper read/write permissions for the application user.
Docker Example:
DATA_PATH=/app/data

STORAGE_TYPE

Type: String (local or minio)
Required: No
Default: local
Storage backend type for file uploads.
STORACE_TYPE=local
Options:
  • local - Store files on local filesystem
  • minio - Store files in MinIO/S3-compatible storage (requires additional MinIO configuration)
MinIO support is currently commented out in the codebase. Use local storage for current deployments.

Database Configuration

These variables are used to construct the DATABASE_URL in Docker Compose setups:

DB_HOST

Type: String
Default: localhost
PostgreSQL database host.
DB_HOST=localhost

POSTGRES_USER

Type: String
Required: Yes (for Docker Compose)
PostgreSQL database username.
POSTGRES_USER=your_pg_user_here

POSTGRES_PASSWORD

Type: String
Required: Yes (for Docker Compose)
PostgreSQL database password.
POSTGRES_PASSWORD=your_pg_passwd_here
Use a strong password in production. Never use default or example passwords.

POSTGRES_DB

Type: String
Required: Yes (for Docker Compose)
Default: defdrive
PostgreSQL database name.
POSTGRES_DB=defdrive

DB_PORT

Type: Integer
Default: 5432
PostgreSQL database port.
DB_PORT=5432

DB_DATA

Type: String (Directory path)
Default: ./data/postgres
Directory path for PostgreSQL data files (used in local Docker volumes).
DB_DATA=./data/postgres

System Configuration

TZ

Type: String (Timezone)
Default: Asia/Kolkata
Timezone for the application container.
TZ=Asia/Kolkata
Other Examples:
TZ=America/New_York
TZ=Europe/London
TZ=UTC

UID

Type: Integer
Default: 1000
User ID for file permissions.
UID=1000

GID

Type: Integer
Default: 1000
Group ID for file permissions.
GID=1000

MinIO Configuration (Optional)

MinIO support is currently commented out in the Docker Compose configuration. These variables are for future use.

MINIO_ROOT_USER

Type: String MinIO root username.
MINIO_ROOT_USER=your_minio_user_here

MINIO_ROOT_PASSWD

Type: String MinIO root password.
MINIO_ROOT_PASSWD=your_minio_passwd_here

MINIO_PORT

Type: Integer
Default: 9000
MinIO API port.
MINIO_PORT=9000

MINIO_CONSOLE_PORT

Type: Integer
Default: 9001
MinIO console port.
MINIO_CONSOLE_PORT=9001

MINIO_HOST

Type: String
Default: localhost
MinIO server host.
MINIO_HOST=localhost

MINIO_BUCKET

Type: String
Default: msm
MinIO bucket name for file storage.
MINIO_BUCKET=msm

MINIO_DATA

Type: String (Directory path)
Default: ./data/minio
Directory path for MinIO data.
MINIO_DATA=./data/minio

Complete Example

Local Development

# User/Group IDs
UID=1000
GID=1000

# DefDrive Configuration
DATA_PATH=./data
PORT=5050
HOST_URL=http://localhost:5050
JWT_SECRET=your_secret_key_here
STORAGE_TYPE=local

# Database Configuration
DB_HOST=localhost
POSTGRES_USER=defdrive_dev
POSTGRES_PASSWORD=dev_password_123
POSTGRES_DB=defdrive
DB_DATA=./data/postgres
DB_PORT=5432
TZ=America/New_York

# Constructed DATABASE_URL
DATABASE_URL=postgres://defdrive_dev:dev_password_123@localhost:5432/defdrive

Production (Docker Compose)

# User/Group IDs
UID=1000
GID=1000

# DefDrive Configuration
DATA_PATH=/app/data
PORT=8080
HOST_URL=https://drive.yourdomain.com
JWT_SECRET=<use openssl rand -base64 32 to generate>
STORAGE_TYPE=local

# Database Configuration
POSTGRES_USER=defdrive_prod
POSTGRES_PASSWORD=<strong_random_password>
POSTGRES_DB=defdrive
DB_PORT=5432
TZ=UTC

# DATABASE_URL is constructed automatically in compose.yaml

Security Best Practices

Follow these security guidelines for production deployments:
  1. Never commit .env files to version control
    • Add .env to .gitignore
    • Use .env.example as a template
  2. Use strong secrets for production
    • Generate JWT_SECRET with cryptographically secure random data
    • Use complex database passwords
  3. Restrict database access
    • Don’t expose PostgreSQL port publicly
    • Use strong authentication
  4. Use HTTPS in production
    • Set HOST_URL to use https://
    • Configure SSL/TLS with a reverse proxy
  5. Secure file storage
    • Set appropriate permissions on DATA_PATH
    • Regularly backup uploaded files

Troubleshooting

Environment Variables Not Loading

If environment variables aren’t being recognized:
  1. Verify .env file exists in the root directory
  2. Check for syntax errors in .env (no spaces around =)
  3. Restart the application after changes

Database Connection Errors

If you see “DATABASE_URL environment variable not set”:
  1. Ensure DATABASE_URL is set in your .env file
  2. Verify the format: postgres://user:pass@host:port/database
  3. Check that PostgreSQL is running and accessible

JWT Token Issues

If authentication fails:
  1. Verify JWT_SECRET is set and consistent
  2. Don’t change JWT_SECRET in production (invalidates all tokens)
  3. Ensure the secret is the same across all instances

Next Steps

Build docs developers (and LLMs) love