Environment Variables
The LoL Tracker Backend uses environment variables to manage sensitive configuration data. All environment variables are stored in a.env file and loaded using the dotenv package.
Loading Environment Variables
At the top ofindex.js, environment variables are loaded:
index.js
This line must be called before accessing any
process.env variables to ensure they’re loaded correctly.Required Variables
Your Riot Games Developer API key. This is used to authenticate all requests to the Riot Games API.How to set it:How it’s used in the code:
.env
index.js
Server Configuration
The server configuration is defined inindex.js and controls how the Express application runs.
Port Configuration
The server listens on port 3000 by default:index.js
How to change the port
How to change the port
To run the server on a different port, modify the Or make it configurable via environment variables:Then add to
PORT constant:index.js
index.js
.env:.env
CORS Configuration
The server uses the cors middleware to handle Cross-Origin Resource Sharing:index.js
- Development
- Production
Default configuration allows all origins:This is perfect for local development when your frontend and backend are on different ports.
index.js
JSON Body Parser
The server is configured to parse JSON request bodies:index.js
req.body.
API Request Configuration
The backend uses axios for making HTTP requests to the Riot Games API.Axios Configuration
Every request to the Riot API includes authentication headers:index.js
- Base URL: Different Riot API endpoints use different regional URLs (
americas,la2, etc.) - Headers: All requests include
X-Riot-Tokenheader with the API key - Authentication: API key is loaded from
process.env.RIOT_API_KEY
Regional Endpoints Used
The application connects to multiple Riot API regions:Configuration Best Practices
Security
- Never hardcode API keys in source code
- Always use
.envfor sensitive data - Keep
.envin.gitignore - Use different API keys for dev/prod
Performance
- Implement request caching for frequently accessed data
- Use connection pooling for database connections
- Enable compression middleware for responses
- Monitor API rate limits
Error Handling
- Implement global error handler middleware
- Log errors to monitoring service
- Return user-friendly error messages
- Never expose internal errors to clients
Environment Management
- Create separate
.env.developmentand.env.production - Document all required environment variables
- Validate env vars on server startup
- Use defaults for non-sensitive config
Example .env File
Create a.env file in your project root with the following structure:
.env
Verifying Configuration
To verify your configuration is working correctly:Next Steps
Authentication Guide
Learn how to obtain and use Riot API keys
API Overview
Explore all available endpoints and their usage