Installation
Installation
Section titled “Installation”Get started with the iRacing Data Client SDK in your project.
Prerequisites
Section titled “Prerequisites”Before installing the Data Client, ensure you have:
- Node.js 18+ or a modern browser environment with fetch support
- npm, yarn, or pnpm package manager
- An active iRacing subscription with valid credentials
- TypeScript 5.0+ (optional, but recommended for the best experience)
Package Installation
Section titled “Package Installation”npm install iracing-data-clientyarn add iracing-data-clientpnpm add iracing-data-clientBasic Setup
Section titled “Basic Setup”-
Import the Data Client
import { IRacingDataClient } from 'iracing-data-client'; -
Initialize with OAuth credentials
const iracing = new IRacingDataClient({auth: {type: 'password-limited',clientId: process.env.IRACING_CLIENT_ID,clientSecret: process.env.IRACING_CLIENT_SECRET,username: process.env.IRACING_USERNAME,password: process.env.IRACING_PASSWORD,},}); -
Make your first API call
const tracks = await iracing.track.get();console.log(`Found ${tracks.length} tracks`);
Configuration Options
Section titled “Configuration Options”The SDK accepts these configuration options:
interface IRacingClientOptions { auth: AuthConfig; fetchFn?: FetchLike; validateParams?: boolean; validateSemanticParams?: boolean; stores?: HttpClientStores;}See the Authentication guide for details on the AuthConfig types.
Environment Variables
Section titled “Environment Variables”The recommended approach is to use environment variables:
const iracing = new IRacingDataClient({ auth: { type: 'password-limited', clientId: process.env.IRACING_CLIENT_ID, clientSecret: process.env.IRACING_CLIENT_SECRET, username: process.env.IRACING_USERNAME, password: process.env.IRACING_PASSWORD, },});Create a .env file (don’t commit to git):
IRACING_CLIENT_ID=your-client-idIRACING_CLIENT_SECRET=your-client-secretIRACING_USERNAME=your-iracing-emailIRACING_PASSWORD=your-iracing-passwordTypeScript Setup
Section titled “TypeScript Setup”The SDK includes TypeScript definitions out of the box. For the best experience:
-
Ensure TypeScript is installed
Terminal window npm install --save-dev typescriptTerminal window npm install --save-dev @types/node -
Configure tsconfig.json
{"compilerOptions": {"target": "ES2022","module": "ESNext","moduleResolution": "bundler","lib": ["ES2022"],"strict": true,"esModuleInterop": true,"skipLibCheck": true,"forceConsistentCasingInFileNames": true}} -
Enable type checking
Your IDE should now provide full IntelliSense support and type checking for all SDK methods.
Node.js Compatibility
Section titled “Node.js Compatibility”Works out of the box with native fetch support:
const iracing = new IRacingDataClient({ auth: { /* ... */ },});Requires a fetch polyfill:
npm install node-fetchimport fetch from 'node-fetch';
const iracing = new IRacingDataClient({ auth: { /* ... */ }, fetchFn: fetch as any,});Browser Usage
Section titled “Browser Usage”The SDK can be used in browser environments with some considerations:
Recommended Browser Setup
Section titled “Recommended Browser Setup”// In a secure backend API route or serverless functionexport async function getIRacingData() { const iracing = new IRacingDataClient({ auth: { type: 'password-limited', clientId: process.env.IRACING_CLIENT_ID, clientSecret: process.env.IRACING_CLIENT_SECRET, username: process.env.IRACING_USERNAME, password: process.env.IRACING_PASSWORD, }, });
return await iracing.track.get();}CORS Considerations
Section titled “CORS Considerations”The iRacing API does not support CORS for browser requests. You’ll need to:
- Use a backend proxy server
- Deploy serverless functions (Vercel, Netlify, AWS Lambda)
- Use a CORS proxy service (development only)
Environment Setup Examples
Section titled “Environment Setup Examples”import { IRacingDataClient } from 'iracing-data-client';
const iracing = new IRacingDataClient({ auth: { type: 'password-limited', clientId: process.env.IRACING_CLIENT_ID!, clientSecret: process.env.IRACING_CLIENT_SECRET!, username: process.env.IRACING_USERNAME!, password: process.env.IRACING_PASSWORD!, },});
export async function GET() { const data = await iracing.track.get(); return Response.json(data);}import express from 'express';import { IRacingDataClient } from 'iracing-data-client';
const app = express();const iracing = new IRacingDataClient({ auth: { type: 'password-limited', clientId: process.env.IRACING_CLIENT_ID!, clientSecret: process.env.IRACING_CLIENT_SECRET!, username: process.env.IRACING_USERNAME!, password: process.env.IRACING_PASSWORD!, },});
app.get('/api/tracks', async (req, res) => { const data = await iracing.track.get(); res.json(data);});Verify Installation
Section titled “Verify Installation”Test your setup with this simple script:
import { IRacingDataClient } from 'iracing-data-client';
async function testConnection() { try { const iracing = new IRacingDataClient({ auth: { type: 'password-limited', clientId: process.env.IRACING_CLIENT_ID!, clientSecret: process.env.IRACING_CLIENT_SECRET!, username: process.env.IRACING_USERNAME!, password: process.env.IRACING_PASSWORD!, }, });
const tracks = await iracing.track.get(); console.log('Connected successfully!'); console.log(`Found ${tracks.length} tracks`); } catch (error) { console.error('Connection failed:', error); }}
testConnection();Troubleshooting
Section titled “Troubleshooting”If you get authentication errors:
- Verify your email and password are correct
- Check if your iRacing subscription is active
- Ensure you’re not hitting rate limits
- Try logging into the iRacing website to verify credentials
For network-related issues:
- Check your internet connection
- Verify firewall settings allow HTTPS requests
- Ensure Node.js has network access
- Try using a custom fetch implementation
If TypeScript isn’t working properly:
- Ensure TypeScript 5.0+ is installed
- Check your tsconfig.json settings
- Restart your TypeScript language server
- Verify moduleResolution is set correctly
Next Steps
Section titled “Next Steps”Now that you have the Data Client installed, check out:
- Quick Start Guide - Build your first application
- Authentication Guide - Learn about authentication options
- API Reference - Explore available services and methods