2017-12-17 18:16:04 +01:00
# `departures(station, [opt])`
`station` must be in one of these formats:
```js
// a station ID, in a format compatible to the profile you use
'900000013102'
// an FPTF `station` object
{
type: 'station',
id: '900000013102',
name: 'foo station',
location: {
type: 'location',
latitude: 1.23,
longitude: 3.21
}
}
```
With `opt` , you can override the default options, which look like this:
```js
{
2018-06-13 20:25:56 +02:00
// todo: products
2017-12-17 18:16:04 +01:00
when: new Date(),
direction: null, // only show departures heading to this station
2018-06-28 13:00:33 +02:00
duration: 10, // show departures for the next n minutes
2020-03-25 21:54:38 +01:00
results: null, // max. number of results; `null` means "whatever HAFAS wants"
2020-03-18 20:04:39 +01:00
subStops: true, // parse & expose sub-stops of stations?
entrances: true, // parse & expose entrances of stops/stations?
2019-01-23 13:03:01 +08:00
linesOfStops: false, // parse & expose lines at the stop/station?
2018-07-09 12:40:38 +02:00
remarks: true, // parse & expose hints & warnings?
2018-12-27 20:17:23 +01:00
stopovers: false, // fetch & parse previous/next stopovers?
2018-07-10 19:01:40 +02:00
// departures at related stations
// e.g. those that belong together on the metro map.
includeRelatedStations: true,
2018-07-09 12:40:38 +02:00
language: 'en' // language to get results in
2017-12-17 18:16:04 +01:00
}
```
## Response
2018-09-22 19:24:34 +02:00
*Note:* As stated in the [*Friendly Public Transport Format* `1.2.0` ](https://github.com/public-transport/friendly-public-transport-format/tree/1.2.0 ), the `when` field includes the current delay. The `delay` field, if present, expresses how much the former differs from the schedule.
2017-12-17 18:16:04 +01:00
2018-06-29 14:42:40 +02:00
You may pass the `tripId` field into [`trip(id, lineName, [opt])` ](trip.md) to get details on the vehicle's trip.
2017-12-17 18:16:04 +01:00
2018-01-05 15:01:32 +01:00
As an example, we're going to use the [VBB profile ](../p/vbb ):
2017-12-17 18:16:04 +01:00
```js
const createClient = require('hafas-client')
const vbbProfile = require('hafas-client/p/vbb')
2018-07-19 21:55:03 +02:00
const client = createClient(vbbProfile, 'my-awesome-program')
2017-12-17 18:16:04 +01:00
// S Charlottenburg
2018-04-17 17:58:55 +02:00
client.departures('900000024101', {duration: 3})
2017-12-17 18:16:04 +01:00
.then(console.log)
.catch(console.error)
```
The response may look like this:
```js
[ {
2018-06-26 14:57:02 +02:00
tripId: '1|31431|28|86|17122017',
2019-12-10 19:40:13 +01:00
trip: 31431,
direction: 'S Spandau',
line: {
type: 'line',
id: '18299',
fahrtNr: '12345',
mode: 'train',
product: 'suburban',
public: true,
name: 'S9',
symbol: 'S',
nr: 9,
metro: false,
express: false,
night: false,
operator: {
type: 'operator',
id: 's-bahn-berlin-gmbh',
name: 'S-Bahn Berlin GmbH'
}
},
2018-07-13 11:34:54 +02:00
stop: {
2017-12-17 18:16:04 +01:00
type: 'station',
id: '900000024101',
name: 'S Charlottenburg',
location: {
type: 'location',
latitude: 52.504806,
longitude: 13.303846
},
products: {
2018-01-05 21:33:03 +01:00
suburban: true,
subway: false,
tram: false,
bus: true,
ferry: false,
express: false,
regional: true
2017-12-17 18:16:04 +01:00
}
},
2019-12-10 19:40:13 +01:00
2019-04-23 17:55:46 +02:00
when: '2017-12-17T19:32:00+01:00',
2019-12-10 19:40:13 +01:00
plannedWhen: '2017-12-17T19:32:00+01:00',
2018-06-30 14:30:17 +02:00
delay: null,
platform: '2',
2019-12-10 19:40:13 +01:00
plannedPlatform: '2'
2017-12-17 18:16:04 +01:00
}, {
2017-12-18 21:11:35 +01:00
cancelled: true,
2019-12-10 19:40:13 +01:00
tripId: '1|30977|8|86|17122017',
trip: 30977,
direction: 'S Westkreuz',
2017-12-17 18:16:04 +01:00
line: {
type: 'line',
id: '16441',
2018-08-22 19:02:56 +02:00
fahrtNr: '54321',
2017-12-17 18:16:04 +01:00
mode: 'train',
product: 'suburban',
2018-07-16 12:39:13 +02:00
public: true,
name: 'S5',
2017-12-17 18:16:04 +01:00
symbol: 'S',
nr: 5,
metro: false,
express: false,
night: false,
2018-01-05 18:46:19 +01:00
operator: { /* … */ }
2017-12-17 18:16:04 +01:00
},
2019-12-10 19:40:13 +01:00
stop: { /* … */ },
when: null,
plannedWhen: '2017-12-17T19:33:00+01:00'
delay: null,
platform: null,
plannedPlatform: '2',
prognosedPlatform: '2'
2017-12-17 18:16:04 +01:00
}, {
2018-06-26 14:57:02 +02:00
tripId: '1|28671|4|86|17122017',
2017-12-17 18:16:04 +01:00
trip: 28671,
2019-12-10 19:40:13 +01:00
direction: 'U Rudow',
2017-12-17 18:16:04 +01:00
line: {
type: 'line',
id: '19494',
2018-08-22 19:02:56 +02:00
fahrtNr: '11111',
2017-12-17 18:16:04 +01:00
mode: 'train',
product: 'subway',
2018-07-16 12:39:13 +02:00
public: true,
name: 'U7',
2017-12-17 18:16:04 +01:00
symbol: 'U',
nr: 7,
metro: false,
express: false,
night: false,
2018-01-05 18:46:19 +01:00
operator: { /* … */ }
2017-12-17 18:16:04 +01:00
},
2019-12-10 19:40:13 +01:00
stop: { /* … */ },
when: '2017-12-17T19:35:00+01:00',
plannedWhen: '2017-12-17T19:35:00+01:00',
delay: 0,
platform: null,
plannedPlatform: null
2017-12-17 18:16:04 +01:00
} ]
```