Prerequisites
Before you begin, ensure you have the following installed on your system:Node.js
Version 14.x or higher recommended
npm
Comes bundled with Node.js
Installation Steps
Install Dependencies
Install all required npm packages using the package manager:This will install the following dependencies:
- express (v5.2.1) - Web framework for Node.js
- axios (v1.13.5) - HTTP client for making API requests
- cors (v2.8.6) - Middleware for enabling CORS
- dotenv (v17.3.1) - Environment variable management
All dependencies are listed in
package.json and will be installed automatically.Configure Environment Variables
Create a Add your Riot Games API key to the To obtain a Riot Games API key, visit Riot Developer Portal and sign in with your Riot account.
.env file in the root directory of the project:.env file:.env
Server Configuration
The server is configured inindex.js with the following settings:
index.js
What Each Line Does:
- Line 1-3: Import required dependencies (Express, CORS, Axios)
- Line 4: Load environment variables from
.envfile using dotenv - Line 6: Initialize Express application
- Line 7: Set the server port to 3000
- Line 9: Enable CORS to allow cross-origin requests from frontend applications
- Line 10: Enable JSON body parsing for incoming requests
Common Setup Issues
Port 3000 is already in use
Port 3000 is already in use
If you see an error that port 3000 is already in use:Solution 1: Change the port in Solution 2: Kill the process using port 3000:
index.js:Module not found errors
Module not found errors
If you encounter module import errors:
- Delete
node_modulesand reinstall:
- Clear npm cache:
RIOT_API_KEY not found
RIOT_API_KEY not found
If you see API key related errors:
- Ensure
.envfile exists in the root directory - Verify the
.envfile contains:RIOT_API_KEY=your_key_here - Restart the server after creating/modifying
.env - Check that
require('dotenv').config()is called at the top ofindex.js
CORS errors in browser
CORS errors in browser
If you’re getting CORS errors when connecting from a frontend:The server already has CORS enabled by default:This allows requests from any origin. For production, you should restrict origins:
Next Steps
Configuration
Learn about environment variables and server configuration
Authentication
Set up Riot API authentication and understand rate limits
API Endpoints
Explore available API endpoints
Quick Start
Make your first API request