Home

Awesome

flix

JavaScript client for the FlixBus (Meinfernbus) / FlixTrain API. Inofficial, using endpoints by FlixMobility. Ask them for permission before using this module in production.

This module conforms to the FPTI-JS 0.3.2 standard for JavaScript public transportation modules.

npm version Build Status license fpti-js version chat on gitter

Installation

npm install flix

Usage

const flix = require('flix')

The flix module conforms to the FPTI-JS 0.3.2 standard for JavaScript public transportation modules and exposes the following methods:

MethodFeature descriptionFPTI-JS 0.3.2
stations.all([opt])All stations of the Flix network, such as Berlin central bus station or Frankfurt Hbf✅ yes
regions.all([opt])All regions (cities) of the Flix network, such as Berlin or Frankfurt✅ yes
journeys(origin, destination, [opt])Journeys between stations or regions✅ yes

stations.all([opt])

Get all stations of the Flix network, such as Berlin central bus station or Frankfurt Hbf. See this method in the FPTI-JS 0.3.2 spec.

Supported Options

AttributeDescriptionFPTI-specValue typeDefault
apiKeyCustom Flix API keyStringdefault api key

Example

const flix = require('flix')
const stationStream = flix.stations.all()

stationStream.on('data', item => {
    // item is an FPTF station object
    console.log(item)
})
{
    type: "station",
    id: "1",
    name: "Berlin central bus station",
    location: {
        type: "location",
        longitude: 13.279399,
        latitude: 52.507171,
        address: "Masurenallee 4-6, 14057 Berlin, Germany",
        country: {
            name: "Germany",
            code: "DE"
        },
        zip: "14057",
        street: "Masurenallee 4-6"
    },
    slug: "berlin-zob",
    aliases: [],
    regions: [
        "88"
    ],
    connections: [
        2,
        3,
        4,
        5,
        8,
        9
        // …
    ],
    importance: 100
}

regions.all([opt])

Get all regions of the Flix network, such as Berlin or Frankfurt. See this method in the FPTI-JS 0.3.2 spec.

Supported Options

AttributeDescriptionFPTI-specValue typeDefault
apiKeyCustom Flix API keyStringdefault api key

Example

const flix = require('flix')
const regionStream = flix.regions.all()

regionStream.on('data', item => {
    // item is an FPTF region object
    console.log(item)
})
{
    type: "region",
    id: "88",
    name: "Berlin",
    location: {
        type: "location",
        longitude: 13.404616,
        latitude: 52.486081,
        country: {
            name: "Germany",
            code: "DE"
        }
    },
    class: "A",
    stations: [
        "1",
        "20688",
        "1224",
        "20678",
        "481"
        // …
    ],
    connections: [
        89,
        90,
        91,
        92,
        93,
        94,
        96,
        97,
        98
        // …
    ],
    slug: "berlin"
}

journeys(origin, destination, [opt])

Find journeys between stations or regions. See this method in the FPTI-JS 0.3.2 spec. Note that origin and destination must have the same type (so either both region or both station).

Supported Options

AttributeDescriptionFPTI-specValue typeDefault
whenJourney date, synonym to departureAfterDatenew Date()
departureAfterList journeys with a departure (first leg) after this dateDatenew Date()
resultsMax. number of results returnedNumbernull
intervalResults for how many minutes after when/departureAfterNumbernull
transfersMax. number of transfersNumbernull
currencyCurrency for journey.priceISO 4217 codeEUR
languageLanguage of the resultsISO 639-1 codeen
adultsNumber of traveling adultsNumber1
childrenNumber of traveling childrenNumber0
bicyclesNumber of traveling bicyclesNumber0
apiKeyCustom Flix API keyStringdefault api key

Note that, unless opt.interval is specified, the module will return journeys that start after when/departureAfter, but before the beginning of the following calendar day.

Example

// journeys between stations
const berlinZOB = '1' // station id
const hamburgCentral = { // FPTF station
	type: 'station',
	id: '36'
	// …
}
flix.journeys(berlinZOB, hamburgCentral, { when: new Date('2019-06-27T05:00:00+0200'), currency: 'PLN' }).then(…)

// journeys between regions
const berlin = { // FPTF region
    type: 'region',
    id: '88'
    // …
}
const hamburg = { // FPTF region
	type: 'region',
	id: '118'
	// …
}
flix.journeys(berlin, hamburg, { when: new Date('2019-06-27T05:00:00+0200'), transfers: 0 }).then(…)
{
    type: "journey",
    id: "direct-80979121-1-36",
    legs: [
        {
            origin: {
                type: "station",
                id: "1",
                name: "Berlin central bus station",
                importance: 100
            },
            destination: {
                type: "station",
                id: "36",
                name: "Hamburg ZOB",
                importance: 100
            },
            departure: "2019-06-27T06:45:00+02:00",
            arrival: "2019-06-27T10:00:00+02:00",
            operator: {
                type: "operator",
                id: "mfb",
                name: "FlixBus DACH GmbH",
                url: "http://flixbus.de",
                address: "Karl-Liebknecht-Straße 33, D-10178 Berlin"
            },
            mode: "bus",
            public: true
        }
    ],
    status: "available",
    borders: false,
    info: {
        title: null,
        hint: null,
        message: null,
        warnings: []
    },
    price: {
        amount: 9.99,
        currency: "EUR",
        discounts: null,
        saleRestriction: false,
        available: true,
        url: "https://shop.global.flixbus.com/s?departureCity=88&arrivalCity=118&departureStation=1&arrivalStation=36&rideDate=27.06.2019&currency=EUR&adult=1&children=0&bike_slot=0"
    }
}

Similar Projects

Contributing

If you found a bug or want to propose a feature, feel free to visit the issues page.