Awesome
interrail
Find european train stations and journeys. Client for the European Interrail / EuRail API. Inofficial, using endpoints by Interrail/EuRail. 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.
Installation
npm install interrail
Usage
const interrail = require('interrail')
The interrail
module conforms to the FPTI-JS 0.3.2
standard for JavaScript public transportation modules and exposes the following methods:
Method | Feature description | FPTI-JS 0.3.2 |
---|---|---|
stations.search(query, [opt]) | Search stations by query. | ✅ yes |
journeys(origin, destination, [opt]) | Journeys between stations | ✅ yes |
stations.search(query, [opt])
Search stations by query. See this method in the FPTI-JS 0.3.2
spec.
Supported Options
Attribute | Description | FPTI-spec | Value type | Default |
---|---|---|---|---|
results | Max. number of results returned | ✅ | Number | null |
Example
interrail.stations.search('Ljubl', { results: 1 }).then(…)
[
{
"type": "station",
"id": "7942300",
"name": "LJUBLJANA (Slovenia)",
"location": {
"type": "location",
"longitude": 14.51028,
"latitude": 46.058057
},
"weight": 12185,
"products": 28
}
]
journeys(origin, destination, [opt])
Find journeys between stations. See this method in the FPTI-JS 0.3.2
spec.
Supported Options
Attribute | Description | FPTI-spec | Value type | Default |
---|---|---|---|---|
when | Journey date, synonym to departureAfter | ✅ | Date | new Date() |
departureAfter | List journeys with a departure (first leg) after this date | ✅ | Date | new Date() |
results | Max. number of results returned | ✅ | Number | null |
interval | Results for how many minutes after when /departureAfter | ✅ | Number | null |
transfers | Max. number of transfers | ✅ | Number | null |
language | Language of the results | ❌ | ISO 639-1 code | null |
Example
const berlin = '8065969' // station id
const ljubljana = { // FPTF station
type: 'station',
id: '7942300',
name: 'Ljubljana'
// …
}
interrail.journeys(berlin, ljubljana, { when: new Date('2018-11-02T05:00:00+0200') }).then(…)
[
{
"id": "8065969-2018-11-02t06-37-00…",
"legs": [
{
"arrival": "2018-11-02T06:54:00+01:00",
"departure": "2018-11-02T06:37:00+01:00",
"destination": {
"id": "8003025",
"location": {
"latitude": 52.534722,
"longitude": 13.196947,
"type": "location"
},
"name": "BERLIN-SPANDAU (Germany)",
"type": "station"
},
"id": "8065969-2018-11-02t06-37-00-01-00-8003025-2018-11-02t06-54-00-01-00-rb-18604",
"line": {
"id": "rb-18604",
"mode": "train",
"name": "RB 18604",
"public": true,
"type": "line"
},
"mode": "train",
"operator": "interrail",
"origin": {
"id": "8065969",
"location": {
"latitude": 52.525553,
"longitude": 13.369441,
"type": "location"
},
"name": "BERLIN HBF (Germany)",
"type": "station"
},
"public": true
}
// …
{
"arrival": "2018-11-02T18:32:00+01:00",
"departure": "2018-11-02T12:17:00+01:00",
"destination": {
"id": "7942300",
"location": {
"latitude": 46.058057,
"longitude": 14.51028,
"type": "location"
},
"name": "LJUBLJANA (Slovenia)",
"type": "station"
},
"id": "8020347-2018-11-02t12-17-00-01-00-7942300-2018-11-02t18-32-00-01-00-ec-113",
"line": {
"id": "ec-113",
"mode": "train",
"name": "EC 113",
"public": true,
"type": "line"
},
"mode": "train",
"operator": "interrail",
"origin": {
"id": "8020347",
"location": {
"latitude": 48.140274,
"longitude": 11.55833,
"type": "location"
},
"name": "MUENCHEN HBF (Germany)",
"type": "station"
},
"public": true
}
],
"type": "journey"
}
// …
]
Contributing
If you found a bug or want to propose a feature, feel free to visit the issues page.