This document provides step-by-step instructions on how to use the airport-data-js
library in a Node.js environment.
-
Install NodeJS Ensure you have Node.js installed.
-
Initialize a new Node.js project (if you haven't already):
npm init -y
-
Install the
airport-data-js
library:npm install airport-data-js
-
Import the library in your Node.js script:
const airports = require('airport-data-js');
Use the available methods to fetch airport data:
-
By IATA Code:
const dataByIata = await airports.getAirportByIata('MAA'); console.log(dataByIata);
-
By ICAO Code:
const dataByIcao = await airports.getAirportByIcao('VOMM'); console.log(dataByIcao);
-
By City Code:
const dataByCity = await airports.getAirportByCityCode('NYC'); console.log(dataByCity);
... and so on for other methods.
Each method returns a promise. Handle errors using try/catch
:
try {
const data = await airports.getAirportByIata('AAA');
console.log(data);
} catch (error) {
console.error('Failed to fetch data:', error.message);
}
- The library fetches data based on the provided codes. Ensure the codes are valid and in the expected format.
- For any issues or further documentation, refer to the main README.md.