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, testAuthentication & Security
string
required
Secret key used to sign JWT tokens for authentication.
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.
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
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.
