Overview
The E-commerce API requires several environment variables to function properly. This guide covers all required and optional configuration settings.Required Environment Variables
Database Configuration
The API uses MySQL as its database. Configure the connection using theDATABASE_URL variable:
mysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE]
The
DATABASE_URL is validated at startup. The application will throw an error if this variable is missing.JWT Authentication
Configure JSON Web Token settings for user authentication:- Used to sign and verify JWT tokens
- Should be a strong, random string (minimum 32 characters recommended)
- Never commit this value to version control
- Token expiration time
- Default:
"1h"(1 hour) - Accepts values like:
"15m","1h","7d"
Cloudinary Configuration
The API uses Cloudinary for image storage. All three variables are required:Sign up for Cloudinary
Create a free account at cloudinary.com
Optional Environment Variables
Node Environment
"development"(default): Enables detailed error messages"production": Optimized for production with minimal error details
Frontend URL
"http://localhost:3001"
Configuration File Structure
The configuration is loaded and validated inbackend/src/config/index.ts:5-19:
Complete .env Template
Create a.env file in the backend/ directory:
Docker Compose Variables
When using Docker Compose, additional MySQL variables are required in the root.env:
These variables are only used by the
docker-compose.yml file to configure the MySQL container. The backend uses DATABASE_URL from backend/.env.Validation on Startup
The application performs validation when starting:- Config validation (
config/index.ts) - Checks JWT and database variables - Cloudinary validation (
config/cloudinary.ts:5-9) - Verifies all three Cloudinary credentials
Next Steps
Docker Deployment
Deploy the application using Docker Compose
Database Migrations
Set up and manage database schema with Prisma