npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flight-data

v2.0.3

Published

Easy to use flight tracking API for Node.js using aviationstack as the source.

Downloads

31

Readme

flight-data

Build Status

Flight-data is an easy to implement flight tracking API for Node.js that uses data from aviationstack to quickly get data on any flight- past, present, or future. But it doesn't stop at flights. Use the airports feature to quickly get highly detailed information on any airport.

Features

Flights

  • Real time flight lookup (multiple flights at a time)
  • Historical flight data
  • Upcoming flight data
  • Detailed departure and arrival information (including gate numbers, runways, and baggage claim areas)
  • Real-time flight data, including current latitude/longitude, heading, and elevation (only available on certain flights)
  • Full support for both IATA and ICAO codes

Airports

  • 6400+ airports
  • Airport lookup (multiple lookups at a time)
  • Lookup by airport-specific codes or by country/city
  • Returns exact latitude/longitude position, timezone, and even airport contact information (available on certain airports)

Installing

npm install flight-data

API Token

Head to aviationstack and obtain a free API token by creating an account.
With a free account, you can make a maximum of 500 API calls per month. You can check your usage from their dashboard.

Usage

Since the API token is private, it's recommended to keep it in a separate configuration file or use it as an environment variable.
Each example uses:

const flightdata = require('flight-data');

Real-time flight lookup

// Get the real-time flight information for flight 2102 to Seattle (SEA)
flightdata.flights(
{
  API_TOKEN: 'YOUR API TOKEN',
  options: {
    limit: 1,
    flight_number: '2102',
    arr_iata: 'SEA'
  }
})
.then(response => {
    ...
  })
.catch(error => {
    ...
});

Airport lookup

// Get full airport information for Seattle-Tacoma International (SEA)
flightdata.airports(
{
  API_TOKEN: 'YOUR API TOKEN',
  options: {
    limit: 1,
    icao_code: 'KSEA'
  }
})
.then(response => {
    ...
  })
.catch(error => {
    ...
});

Historical/Future flight lookup

// Get the flight information for flight 2102 to Seattle (SEA) on May 25th, 2020
flightdata.flights(
{
  API_TOKEN: 'YOUR API TOKEN',
  options: {
    limit: 1,
    flight_number: '2102',
    flight_date: '2020-05-25',
    arr_iata: 'SEA'
  }
})
.then(response => {
    ...
  })
.catch(error => {
    ...
});

Using results

// Get the departure gate for flight 2102 to Seattle (SEA)
flightdata.flights(
{
  API_TOKEN: 'YOUR API TOKEN',
  options: {
    limit: 1,
    flight_number: '2102',
    arr_iata: 'SEA'
  }
})
.then(response => {
    response.data.forEach(element => {
      console.log(element.departure['gate'])
    })
  })
.catch(error => {
    ...
});

A couple notes for dealing with flight lookup results:

The flight lookup module returns a JSON array with this structure:

{
  count: 1,
  data: [
    {
      flight_date: '2020-05-04',
      flight_status: 'cancelled',
      departure: [Object],
      arrival: [Object],
      airline: [Object],
      flight: [Object],
      aircraft: null,
      live: null
    }
  ]
}

This format of return means that to access the flight data, you'll need to use response.data instead of just using response. You can access the count of responses returned by using response.count.
The information returned in some areas of the data section is contained in other arrays. To access this information, use response.data.SECTION['ELEMENT']. For example, to get the departure gate, use response.data.departure['gate']

Airport lookup results structure

The airport lookup module similarly returns a JSON array, but getting results from the array is a slightly different process:

{
  count: 1,
  data: [
    {
      gmt: '-8',
      iata_code: 'SEA',
      city_iata_code: 'SEA',
      icao_code: 'KSEA',
      country_iso2: 'US',
      geoname_id: '5809876',
      latitude: '47.44384',
      longitude: '-122.301735',
      airport_name: 'Seattle-Tacoma International',
      country_name: 'United States',
      phone_number: '206-787-5388',
      timezone: 'America/Los_Angeles'
    }
  ]
}

Results can be accessed from this array through response.data[INDEX].ELEMENT. For example, to get the airport name from this result, use response.data[0].airport_name.

Contributing

Want to contribute? That's great!

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Disclaimer

All data gathered comes from the aviationstack API. They could choose to modify their terms of service at any time. Please see their website and documentation for the most accurate information about their service.

License

MIT