Skip to content
A JavaScript client for Berlin & Brandenburg public transport HAFAS API.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.editorconfig
.gitignore
README.md
example.js
index.js
license.md
package.json
retry.js
throttle.js

README.md

vbb-hafas

A client for the Berlin & Brandenburg public transport service (VBB). It acts as a consistent and straightforward interface on top of a verbose API.

This project is actually a thin wrapper around hafas-client@4. Its docs document the API in general.

Note: You may not want to query the VBB API by yourself. vbb-client is an API-compatible client for vbb-rest, my wrapper API. It also works in the browser.

vbb-rest architecture diagram

npm version dependency status ISC-licensed chat on gitter support me on Patreon

Installing

npm install vbb-hafas

API

Check the docs for hafas-client as well as its VBB-specific customisations.

Usage

const createHafas = require('vbb-hafas')

const hafas = createHafas('my-awesome-program')

As an example, we will search for a journey from Berlin Hauptbahnhof to Berlin Charlottenburg. To get the station IDs, use vbb-stations.

hafas.journeys('900000003201', '900000024101', {results: 1})
.then((journeys) => console.log(journeys[0]))
.catch(console.error)

The output will be an array of journey objects in the Friendly Public Transport Format 1.0.1 format:

[ {
	legs: [ {
		id: '1|50420|0|86|25122017',
		origin: {
			type: 'station',
			id: '900000003201',
			name: 'S+U Berlin Hauptbahnhof',
			location: {
				type: 'location',
				latitude: 52.52585,
				longitude: 13.368928
			},
			products: {
				suburban: true,
				subway: true,
				tram: true,
				bus: true,
				ferry: false,
				express: true,
				regional: true
			}
		},
		departure: '2017-12-26T00:41:00.000+01:00',
		departurePlatform: '14',
		delay: 0,
		destination: {
			type: 'station',
			id: '900000024101',
			name: 'S Charlottenburg',
			location: {
				type: 'location',
				latitude: 52.504806,
				longitude: 13.303846
			},
			products: {
				suburban: true,
				subway: false,
				tram: false,
				bus: true,
				ferry: false,
				express: false,
				regional: true
			}
		},
		arrival: '2017-12-26T00:50:00.000+01:00',
		arrivalPlatform: '4',
		line: {
			type: 'line',
			id: '10',
			name: 'RE1',
			public: true,
			mode: 'train',
			product: 'regional',
			symbol: 'RE',
			nr: 1,
			metro: false,
			express: true,
			night: false,
			class: 64,
			productCode: 6,
			operator: {
				type: 'operator',
				id: 'db-regio-ag',
				name: 'DB Regio AG'
			}
		},
		direction: 'Brandenburg, Hbf'
	} ],
	// all these are from the first leg
	origin: {
		type: 'station',
		id: '900000003201',
		name: 'S+U Berlin Hauptbahnhof',
		location: {
			type: 'location',
			latitude: 52.52585,
			longitude: 13.368928
		},
		products: {
			suburban: true,
			subway: true,
			tram: true,
			bus: true,
			ferry: false,
			express: true,
			regional: true
		}
	},
	departure: '2017-12-26T00:41:00.000+01:00',
	destination: {
		type: 'station',
		id: '900000024101',
		name: 'S Charlottenburg',
		location: {
			type: 'location',
			latitude: 52.504806,
			longitude: 13.303846
		},
		products: {
			suburban: true,
			subway: false,
			tram: false,
			bus: true,
			ferry: false,
			express: false,
			regional: true
		}
	},
	arrival: '2017-12-26T00:50:00.000+01:00'
} ]

Transfer information for journeys

vbb-hafas will try to add transfer information from vbb-change-positions if you pass transferInfo: true as an option.

If it identifies a known transfer, the previous leg will have a arrivalPosition and the next leg will have a departurePosition, indicating the optimal transfer between both platforms. Check out the markup in vbb-change-positions for more details.

Related

Check hafas-client's related libs.

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

You can’t perform that action at this time.