This guide covers all the environment variables needed to run the Crypto Shop Backend application.
Required Environment Variables
Create a .env file in the root directory of your project with the following variables:
Database Configuration
MONGODB_URI=mongodb://localhost:27017/crypto-shop
Connection string for your MongoDB database. This can be a local MongoDB instance or a cloud-hosted database like MongoDB Atlas.
Server Configuration
NODE_ENV=development
PORT=3000
- NODE_ENV: Set to
development for local development or production for production deployments
- PORT: The port number where the server will run (default: 3000)
TRON Network Configuration
TRON_NETWORK=https://nile.trongrid.io
The TRON network endpoint to use:
- Testnet (Nile):
https://nile.trongrid.io
- Mainnet:
https://api.trongrid.io
Use the testnet for development and testing. Only switch to mainnet for production with real transactions.
JWT Authentication
ACCESS_TOKEN_SECRET=your_access_token_secret_here_min_32_chars
REFRESH_TOKEN_SECRET=your_refresh_token_secret_here_min_32_chars
Secure random strings used to sign JWT tokens. These should be:
- At least 32 characters long
- Randomly generated
- Never committed to version control
- Different for each environment
Generate secure secrets using:node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
CORS Configuration
CLIENT_URL=http://localhost:3000
The URL of your frontend application for CORS configuration. This allows your frontend to make authenticated requests to the API.
Complete Example
Here’s a complete .env.example file:
# MongoDB
MONGODB_URI=mongodb://localhost:27017/crypto-shop
# Node Environment
NODE_ENV=development
PORT=3000
# TRON Network (usa Nile para testnet o mainnet para producción)
TRON_NETWORK=https://nile.trongrid.io
# JWT Secrets (genera strings aleatorios seguros)
ACCESS_TOKEN_SECRET=your_access_token_secret_here_min_32_chars
REFRESH_TOKEN_SECRET=your_refresh_token_secret_here_min_32_chars
# Frontend URL (para CORS)
CLIENT_URL=http://localhost:3000
Environment-Specific Settings
NODE_ENV=development
PORT=3000
TRON_NETWORK=https://nile.trongrid.io
CLIENT_URL=http://localhost:3000
Use the Nile testnet for development to avoid real transaction costs.NODE_ENV=production
PORT=3000
TRON_NETWORK=https://api.trongrid.io
CLIENT_URL=https://your-frontend-domain.com
Use mainnet and ensure all secrets are properly secured.
Security Best Practices
Never commit .env files
Add .env to your .gitignore file to prevent accidentally committing sensitive credentials.
Use strong secrets
Generate cryptographically secure random strings for JWT secrets (minimum 32 characters).
Rotate secrets regularly
In production, rotate your JWT secrets periodically and update them across all environments.
Use environment variables in production
Don’t use .env files in production. Instead, use your hosting platform’s environment variable management.