Node.js SDK
Official Node.js client for sportapi. TypeScript types included, async/await native, retry and rate-limit handling built in.
Installation
npm install @sportapi/node
# or
yarn add @sportapi/node
# or
pnpm add @sportapi/nodeQuick start
import { Sportapi } from '@sportapi/node';
const client = new Sportapi(process.env.SPORTAPI_KEY);
const games = await client.nba.scores.live();
console.log(games);Configuration
const client = new Sportapi(process.env.SPORTAPI_KEY, {
timeout: 10_000, // ms
maxRetries: 3,
baseUrl: 'https://api.sportapi.io/v1',
apiVersion: '2025-09-01', // pin to a dated version
fetch: customFetch, // BYO fetch implementation
});API coverage
| Resource | Status |
|---|---|
| NBA | Full |
| NFL | Full |
| MLB | Full |
| NHL | Full |
| Soccer | Full |
| News | Full |
| WebSocket | Full |
| Webhooks | Full |
Error handling
import { Sportapi, RateLimitError, AuthError } from '@sportapi/node';
try {
await client.nba.scores.live();
} catch (e) {
if (e instanceof RateLimitError) {
await sleep(e.retryAfter * 1000);
} else if (e instanceof AuthError) {
console.error('Bad key:', e.message);
} else {
throw e;
}
}The client retries
429 and 5xx automatically with exponential backoff (configurable via maxRetries). You only see an error if retries are exhausted.Streaming (WebSocket)
const stream = client.stream();
stream.subscribe('nba.scores.live');
stream.on('update', game => console.log(game));
stream.on('error', console.error);
// Auto-reconnects with backoff and re-subscribesTypeScript
Full TypeScript definitions included. All response types are exported and can be imported directly:
import type { NBAGame, NewsItem, PaginatedResponse } from '@sportapi/node';Version compatibility
| SDK version | API version | Node.js |
|---|---|---|
| 1.x | v1 (2025-09-01+) | ≥ 18 |