Skip to main content
The Horse Trust platform requires environment variables to be configured for both the server (backend) and client (frontend) applications.

Server Environment Variables

Create a .env file in the server/ directory with the following variables:

Database Configuration

string
required
MongoDB connection string for your database.
Format: mongodb+srv://<username>:<password>@<cluster>/<database>

Server Configuration

number
default:"8031"
Port number where the Express server will run.
string
default:"development"
Environment mode for the application.
Options: development, production, test

Authentication & Security

string
required
Secret key used to sign JWT tokens for authentication.
Use a strong, random string in production. Never commit this value to version control.
string
default:"10d"
JWT token expiration time.
Format: Use time notation like 10d (10 days), 24h (24 hours), 30m (30 minutes)
number
default:"12"
Number of salt rounds for bcrypt password hashing.
Higher values increase security but also increase processing time. 12 is a good balance for production.

CORS Configuration

string
default:"*"
Comma-separated list of allowed origins for CORS.
In production, replace * with specific allowed origins for better security.

Client Environment Variables

Create a .env.local file in the client/ directory with the following variables:

API Configuration

string
required
Base URL for the backend API.
The NEXT_PUBLIC_ prefix makes this variable accessible in the browser.

Cloudinary Configuration

string
required
Your Cloudinary cloud name for image uploads.
string
required
Cloudinary upload preset for handling image uploads.
You need to create this upload preset in your Cloudinary dashboard with unsigned upload enabled.

Example Configuration Files

Server .env Example

Client .env.local Example

Security Best Practices

Never commit .env files to version control!Ensure .env, .env.local, and .env.production are listed in your .gitignore file.
1

Use Strong Secrets

Generate strong, random strings for JWT_SECRET using a password generator or:
2

Restrict CORS Origins

In production, never use CORS_ORIGINS=*. Specify exact domains.
3

Use Environment-Specific Files

Maintain separate configuration files for development, staging, and production.
4

Rotate Secrets Regularly

Update sensitive credentials like JWT_SECRET periodically and after any security incident.

Validation

The server validates required environment variables on startup. If any required variable is missing, the application will fail to start with an error message:
Ensure all required variables are set before running the application.