@flightradar24/fr24sdk

中文文档
0.1.1发布于 2025/11/04MITESM + CJS构建来源已验证近 30 天下载 2301

Official node.js SDK for Flightradar24 API

原始使用文档
文档目录12 节
  1. Features
  2. Installation
  3. Release Version (Recommended for Users)
  4. Development Version (Recommended for Contributors)
  5. SDK Usage Guide
  6. 1. Client Initialization
  7. 2. Accessing API Resources
  8. 3. Resource Examples
  9. 4. Handling Responses
  10. 5. Error Handling
  11. Contributing
  12. License

Flightradar24 Node SDK (fr24sdk)

Node.js SDK for the Flightradar24 API.

Features

  • Access to all Flightradar24 API v1 endpoints.
  • Intuitive client interface: client.airports.getFull("WAW")
  • Robust error handling with custom exceptions.
  • Lightweight input validation for common parameters.
  • Returns plain JavaScript objects and classes for easy data access.

Installation

npm install @flightradar24/fr24sdk

If you want to contribute to the SDK or use the latest unreleased changes:

git clone https://github.com/flightradar24/fr24api-sdk-node.git
cd fr24api-sdk-node

SDK Usage Guide

This guide provides a comprehensive overview of how to use the SDK to interact with the Flightradar24 API.

1. Client Initialization

The Client class is your main entry point to the API.

Using environment variable (recommended):

Make sure you have dotenv installed, then create a .env file in your project root and add your API token:

FR24_API_TOKEN=your_api_token_here

Then, initialize the client:

require('dotenv').config();
const SDK = require('@flightradar24/fr24sdk');

const client = new SDK.Client({
  apiToken: process.env.FR24_API_TOKEN,
  apiVersion: 'v1', // optional, defaults to 'v1'
});

You can also use ESM

import SDK from '@flightradar24/fr24sdk';

const client = new SDK.Client({
  apiToken: process.env.FR24_API_TOKEN,
  apiVersion: 'v1', // optional, defaults to 'v1'
});

2. Accessing API Resources

The client provides access to different API resources as properties. For example:

  • client.airlines: Fetch airline details.
  • client.airports: Fetch airport details.
  • client.live: Get live flight data, including flights within specific geographical bounds.
  • client.historic: Query historic flight information.
  • client.flightSummary: Retrieve summaries for specific flights.
  • client.flightTracks: Access flight track data.
  • client.usage: Check your API usage statistics.

Each resource object has methods to fetch data related to that resource.

3. Resource Examples

Fetching Airport Details

This example demonstrates fetching detailed information for an airport (e.g., Warsaw Chopin Airport - WAW) and accessing its attributes.

require('dotenv').config();
const SDK = require('@flightradar24/fr24sdk');

const client = new SDK.Client({
  apiToken: process.env.FR24_API_TOKEN,
  apiVersion: 'v1',
});

(async () => {
  try {
    const airport = await client.airports.getFull('WAW');
    console.log('Airport (WAW) Full:', airport);
    // Access properties, e.g.:
    // console.log(airport.name);
    // console.log(airport.timezone.name);
  } catch (err) {
    console.error(err);
  } finally {
    client.close();
  }
})();

Other Examples

See examples.js for more usage patterns, including:

  • Fetching flight summaries
  • Fetching airline details
  • Getting live and historic flight positions
  • Fetching flight tracks
  • Checking API usage

4. Handling Responses

API methods return JavaScript objects or class instances that represent the JSON response from the API. You can access data using dot notation, for example:

const airport = await client.airports.getFull('JFK');
console.log(airport.name); // Airport name
console.log(airport.timezone.name); // Timezone name

Some endpoints return arrays or response wrapper classes (e.g., UsageLogSummaryResponse, FlightTracksResponse).

5. Error Handling

The SDK uses custom exceptions to indicate errors. The base exception is Fr24SdkError. More specific errors like ApiError, AuthenticationError, RateLimitError, etc., inherit from it.

Example error handling:

const SDK = require('@flightradar24/fr24sdk');
const { ApiError, AuthenticationError, Fr24SdkError } = require('./src/exceptions');

const client = new SDK.Client({ apiToken: process.env.FR24_API_TOKEN });

(async () => {
  try {
    // Example: Intentionally try to get a non-existent airport
    const airport = await client.airports.getFull('INVALID_IATA');
    if (airport) {
      console.log(airport.name);
    }
  } catch (err) {
    if (err instanceof AuthenticationError) {
      console.error('Authentication failed. Please check your API token.');
    } else if (err instanceof ApiError) {
      console.error('API Error occurred:', err.getMessage());
      console.error('Details:', err.getDetails());
    } else if (err instanceof Fr24SdkError) {
      console.error('An SDK-specific error occurred:', err.message);
    } else {
      console.error('An unexpected error occurred:', err);
    }
  } finally {
    client.close();
  }
})();

Contributing

Contributions are welcome! Please see CONTRIBUTING.md (to be created) for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

版本与发布记录

@flightradar24/fr24sdk 共发布 2 个版本,首次发布于 2025/10/20;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.1latest2025/11/041 年前
0.1.02025/10/201.1 年前

关于 @flightradar24/fr24sdk 的常见问题

@flightradar24/fr24sdk 是什么?

Official node.js SDK for Flightradar24 API

如何安装 @flightradar24/fr24sdk?

在项目目录运行 npm install @flightradar24/fr24sdk,或使用 pnpm add / yarn add / bun add。

@flightradar24/fr24sdk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/flightradar24__fr24sdk 是否存在。

@flightradar24/fr24sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flightradar24/fr24sdk 可以商用吗?

@flightradar24/fr24sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flightradar24/fr24sdk 的下载量有多少?

根据 npm 官方下载统计,@flightradar24/fr24sdk 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,301 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flightradar24/fr24sdk 还在维护吗?

最新版本 0.1.1 发布于 2025/11/04(1 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/10/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。