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/node

Quick 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

ResourceStatus
NBAFull
NFLFull
MLBFull
NHLFull
SoccerFull
NewsFull
WebSocketFull
WebhooksFull

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-subscribes

TypeScript

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 versionAPI versionNode.js
1.xv1 (2025-09-01+)≥ 18