Skip to content

Instantly share code, notes, and snippets.

@linuxgemini
Created June 22, 2026 00:48
Show Gist options
  • Select an option

  • Save linuxgemini/c39ca42f32930bf44ad11c1832e6ec62 to your computer and use it in GitHub Desktop.

Select an option

Save linuxgemini/c39ca42f32930bf44ad11c1832e6ec62 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const IMMFLY_TOKEN = "";
// You can use Immfly's public API if you set this value
// (for example, to "pgt") and set environment variables
// IS_DEVELOPMENT or IS_CLOUD to anything.
const IMMFLY_AIRLINE = "";
class Immfly {
#HOSTNAME;
#API_ENDPOINT;
#TOKEN;
constructor(airline = "", token = "") {
if (typeof airline !== "string") throw new Error('"airline" is invalid');
if (airline !== "") {
// use immfly's public endpoints if requested, otherwise fallback to IFE link
this.#HOSTNAME = (process?.env?.IS_DEVELOPMENT ? `https://${airline}.staging.immfly.io/` : (process?.env?.IS_CLOUD ? `https://${airline}.cloud.immfly.io/` : "https://air.immfly.com/"));
} else {
// use local mockserver if requested, use IFE link if not
this.#HOSTNAME = (process?.env?.IS_DEVELOPMENT ? `http://localhost:3000/` : "https://air.immfly.com/");
}
this.#API_ENDPOINT = `${this.#HOSTNAME}api`;
this.#TOKEN = token;
}
static Client(token = "") {
return new this(token);
}
getToken() {
return this.#TOKEN;
}
setToken(token = "") {
this.#TOKEN = token;
return;
}
async #makeRequest(path = "/", dontUseToken = true, method = "GET") {
const headers = {
"accept": "application/json; version=2",
"referer": this.#HOSTNAME,
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36",
"cache-control": "no-cache",
"pragma": "no-cache"
};
if (!dontUseToken) headers["x-authorization"] = `Token ${this.#TOKEN}`;
const response = await (await fetch(`${this.#API_ENDPOINT}${path}?display_language=EN`, {
method,
headers
})).json();
return response;
}
async getFlightInfo() {
return await this.#makeRequest("/flightinfo/");
}
}
const main = async () => {
const client = Immfly.Client(IMMFLY_AIRLINE, IMMFLY_TOKEN);
const printFlightData = async () => {
try {
const request = await client.getFlightInfo();
const aircraftRegistration = request.aircraft;
const flightID = request.flight_id;
const originCity = request.origin_city;
const originAirport = request.origin_airport;
const destinationCity = request.destination_city;
const destinationAirport = request.destination_airport;
// lat, lon are floats (assuming -180.0 to 180.0 range)
// pitch, roll, yaw and heading are probably in degrees
// altitude is in feet
const { latitude, longitude, pitch, roll, yaw, heading, altitude } = request;
const machSpeed = request.mach_speed;
const groundSpeedInKnots = request.ground_speed;
const outsideTemperatureInDegreesCelsius = request.outside_temperature;
const minutesToDestination = request.time_to_destination;
const isThereWeightOnWheels = request.weight_on_wheels;
console.log(`------
Time: ${(new Date()).toISOString()}
You're flying on ${aircraftRegistration} with flight ID ${flightID}.
Currently flying from ${originCity.name.replace(" "+originCity.code,"")} (${originAirport.iata_code}) to ${destinationCity.name.replace(" "+destinationCity.code,"")} (${destinationAirport.iata_code})
Plane is currently at (${latitude}, ${longitude}).${(!isThereWeightOnWheels && (" Cruising along at "+altitude+" ft, at "+groundSpeedInKnots+" knots (mach "+machSpeed+")"))}
Pitch: ${pitch} degrees
Roll: ${roll} degrees
Yaw: ${yaw} degrees
Heading: ${heading} degrees
${(isThereWeightOnWheels ? "Plane is on ground." : "Still flying, ETA "+minutesToDestination+" minutes.")}
------
`);
} catch (e) {
console.log(`------
Time: ${(new Date()).toISOString()}
API request failed: ${e.stack || e.toString()}
------
`);
}
}
const timer = setInterval(printFlightData, 5000);
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment