Overview
The Crypto Shop Backend requires several environment variables to be configured before running. Copy.env.example to .env and configure the values according to your environment.
Required Variables
Database Configuration
MONGODB_URI
MongoDB connection string for database access
- Use MongoDB Atlas or a managed MongoDB service
- Enable authentication and encryption
- Use connection pooling
- Configure replica sets for high availability
Application Configuration
NODE_ENV
Node.js environment mode
development- Development mode with verbose loggingproduction- Production mode with optimizationstest- Test mode for running tests
PORT
Port number for the Express server
TRON Network Configuration
TRON_NETWORK
TRON blockchain network endpoint URL
MERCHANT_WALLET_ADDRESS
TRON wallet address to receive payments
Alternatively, the system will use the wallet address of the first admin user if this variable is not set.
JWT Authentication
ACCESS_TOKEN_SECRET
Secret key for signing access tokens (JWT)
- Minimum 32 characters
- Use cryptographically secure random string
- Keep secret and never commit to version control
REFRESH_TOKEN_SECRET
Secret key for signing refresh tokens (JWT)
- Minimum 32 characters
- Must be different from
ACCESS_TOKEN_SECRET - Use cryptographically secure random string
CORS Configuration
CLIENT_URL
Frontend application URL for CORS configuration
FRONTEND_URL
Alternative frontend URL (optional, for additional CORS origin)
Configure both
CLIENT_URL and FRONTEND_URL if you have multiple frontend origins that need to access the API.Optional Variables
Rate Limiting
While not explicitly defined in.env.example, you may want to add these:
Logging
Environment-Specific Configurations
Development Environment
Production Environment
Security Best Practices
Never Commit Secrets
Add
.env to .gitignore to prevent committing sensitive dataUse Strong Secrets
Generate secrets with at least 48 bytes of entropy
Rotate Regularly
Change JWT secrets periodically and after security incidents
Environment Isolation
Use different secrets for development, staging, and production
Validation
The application performs basic validation on startup:- Checks for required environment variables
- Validates MongoDB connection
- Verifies TRON network connectivity
- Ensures JWT secrets are configured
Troubleshooting
”MONGODB_URI is not defined”
Ensure you have created a.env file and configured MONGODB_URI.
”Cannot connect to TRON network”
VerifyTRON_NETWORK URL is correct and accessible from your server.
”JWT secret too short”
Generate longer secrets (minimum 32 characters) forACCESS_TOKEN_SECRET and REFRESH_TOKEN_SECRET.
CORS Errors
EnsureCLIENT_URL matches exactly with your frontend origin (including protocol and port).