Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ns-api

fvdm54Unlicense4.1.2TypeScript support: definitely-typed

Public transit data from Nederlandse Spoorwegen API

api, navigation, nl, ns, public transport, railway, traffic, trains, transit, transport, unlicense

readme

ns-api

Access public transit data from Nederlandse Spoorwegen API with node.js

Changelog Build Status Coverage Status

To use this module you need API access credentials, which you can request at Here (Dutch).

Example

const NSAPI = require ('ns-api');
const ns = new NSAPI ({
  key: 'abc123',
});

// Output w/o limits
function out (data) {
  console.dir (data, {
    depth: null,
    colors: true,
  });
}

// Get travel advise
ns.getTrips ({
  fromStation: 'UT',
  toStation: 'AMF',
})
  .then (out)
  .catch (console.error)
;

Installation

npm i ns-api

Configuration

param type default description
key string | One of your API keys
[timeout] number 8000 Request time out in ms
const NSAPI = require ('ns-api');
const ns = new NSAPI ({
  key: 'abc123',
});

Methods

Each method returns a Promise, so make sure to catch the errors properly.

When a method takes arguments they are only accepted in object notation. This way the order no longer matters and it makes it easier to reuse them.

methodName ({ one, two });

I'm not going to outline to full possibilities of each method here, only the parts that adjust the API response or make the request easier. Read the API documentation links to find all available parameters that each method can take.

Reisinformatie

getAllStations

List of all stations

ns.getAllStations()
  .then (data => data.filter (station => station.land === 'NL'))
  .then (data => console.table (data, ['code', 'stationType']))
  .catch (console.error)
;

API documentation

getArrivals

List of arrivals at a station. It requires a station or uicCode.

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getArrivals ({
  dateTime: '2019-05-10',
  station: 'UT',
})
  .then (data => console.table (data, ['name', 'origin', 'actualDateTime']))
  .catch (console.error)
;

API documentation

getCalamities

List of all current calamities

parameter type description
[lang] string Text language
ns.getArrivals ({ lang: 'en' })
  .then (console.log)
  .catch (console.error)
;

API documentation

getDepartures

List all departures at a station. It requires a station or uicCode.

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getDepartures ()
  .then (console.log)
  .catch (console.error)
;

API documentation

getDisruptions

List of disruptions/maintenance.

parameter type description
[actual] boolean Only return disruptions within 2 hours
ns.getDisruptions()
  .then (data => console.table (data, ['titel']))
  .catch (console.error)
;

API documentation

getStationDisruption

List of disruptions at a station

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getStationDisruption ({ dateTime: '2019-05-10' })
  .then (data => console.table (data, ['titel']))
  .catch (console.error)
;

API documentation

getDisruption

Get details about one disruption

parameter type description
type string Disruption type
id string Disruption object ID
ns.getDisruption ({
  type: 'maintenance',
  id: '7001000',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getTrips

Get a list of travel advises

parameter type description
[dateTime] Date or string Limit to starting time, will be converted to the right format
ns.getTrips ({
  dateTime: '2019-05-10 17:40',
  fromStation: 'Amersfoort',
  toStation: 'Den Haag',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getTrip

Get a specific travel advise

parameter type description
ctxRecon string Trip ctxRecon from getTrips()
ns.getTrip ({ ctxRecon: 'abc123' })
  .then (console.log)
  .catch (console.error)
;

API documentation

getPrice

Get pricing for travel between two stations.

parameter type description
fromStation string Station name or ID
toStation string Station name or ID
ns.getPrices ({
  fromStation: 'AMF',
  toStation: 'Den Haag',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getJourney

Get information about a specific journey. You can find the id in the trip data from getTrip() at trip.legs[].journeyDetail[].link.uri. Just use that whole path.

parameter type description
id string Journey ID
ns.getJourney ({
  id: 'HARP_S2S-1|3824|0|784|8052021',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

Places

placesList

Search for places. Returns an array.

argument type description
parameters object See API docs
ns.placesList ({
  q: 'utrecht cs',
});

API documentation

placesGet

Get details about one place. Returns an object.

parameter type description
type string Place type, ex: stationV2
id string Place ID, ex: AMF
[lang] string Response language
ns.placesGet ({
  type: 'stationV2',
  id: 'AMF',
});

API documentation

placesOvfiets

Get a list of OV Fiets locations. Returns an array.

parameter type description
[station_code] string Filter by station
ns.placesOvfiets ({
  station_code: 'AMF',
});

API documentation

Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to https://unlicense.org/

Author

Franklin | Buy me a coffee

changelog

4.1.2 (2023-08-30)

Chores
  • github:
    • Bump github/codeql-action from 1 to 2 (#33) (66b69fb3)
    • Bump actions/checkout from 2 to 3 (#31) (7ffd07d3)
    • Bump actions/setup-node from v2 to v3.0.0 (#30) (f7009d1a)
Refactors

4.1.1 (2021-10-06)

Chores
Refactors
  • doRequest now returns a promise (59235338)
Code Style Changes
Tests

4.1.0 (2021-08-03)

Chores
Documentation Changes
New Features
Bug Fixes
  • Moved API error fallback to bottom (298e9ecd)
  • getPrices() changed response (f59ae268)
Refactors
Code Style Changes
Tests
  • Added getDisruptions actual test (1aff11d2)
  • Fix errors (277a771a)
  • Improve testing and error handling (8aed25f5)
  • Update Travis CI node versions (7afd99ec)
  • config:

4.0.1 (2020-08-31)

Chores
Documentation Changes
Bug Fixes
Tests
  • config:
    • Update Travis node versions (8a92d788)
    • Update Travis node versions and env (6f3312eb)

4.0.0 (2019-12-16)

Breaking Changes
  • Full rewrite to the new NS API (5ca0f6a8)
Chores
Documentation Changes
Refactors
Code Style Changes
  • test: Minor syntax consistency (9a6a5026)
  • package: Removed trailing whitespace from json (9a991ecf)
  • cleanup: Removed unnecessary getTrip() args (031419c9)
Tests

2.0.8 (2017-12-12)

Chores
  • package:
  • develop: Cleanup .gitignore (6a753e7f)
Documentation Changes
  • readme: Minor style changes (789e3ee9)
  • badges: Get bithound badges for master (d2c308ab)
Bug Fixes
Code Style Changes
  • example: Convert to ES6 syntax (1ea95fe0)
Tests
  • main: Fixed ES6 syntax (93e76bc0)
  • style: Convert syntax to ES6 (3f415ab5)
  • config:
    • Remove ecmaVersion from .eslintrc (a3cf2a32)
    • Update Travis CI node versions (f3b23bb7)
    • Replaced node 7 with 8 on Travis CI (6f7da3a9)

2.0.7 (2017-12-12)

2.0.6 (2017-5-16)

Chores
Documentation Changes
  • readme: Add coffee button to Author (204575c3)
Code Style Changes

2.0.5 (2016-10-31)

Chores
  • package:
  • develop: Added bitHound config (040313a6)
Documentation Changes
  • readme: Added linebreak at end (6c74a046)
  • badges: Replaced deps badge, code quality (0011f95d)
Refactors
  • main: No need to wrap body in Buffer (2b8f0f59)
Tests
  • config:
    • Set bitHound long file to 500 lines (045c234b)
    • Use dynamic node versions on Travis CI (86731d5a)
  • lint: Update eslint to ES6 (d6a58f80)

2.0.4 (2016-7-2)

Refactors
  • cleanup: Removed unused iteration from objectOmit (c0852859)

2.0.3 (2016-7-2)

Bug Fixes
  • storingen: Fixed empty dataset handling (820a019c)
Tests
  • tests: Set actual to true for storingen with params (bde8f006)

2.0.2 (2016-7-2)

Chores
Documentation Changes
  • readme:
  • badges: Add coverage status badge (19188006)
Bug Fixes
  • processData: Make sure data is always a Buffer (a0fdd89b)
  • setup: Fixed fatal error when config is missing (1da58df3)
Refactors
  • style:
    • Reduced complexity of methodStoringen (3455c2f2)
    • Reduced complexity of methodStations (8b8d0116)
    • Reduced complexity methodReisadvies (f71bc605)
    • More consistent returns (f3a8d760)
  • request:
  • errors: Generate most errors with makeError() (acc14be2)
  • response: Renamed processResponse to httpResponse (48543393)
  • package:
Tests
  • tests:
    • Do test .prijzen even tough it is not available (4b7e5dbc)
    • Check err.message on .vertrektijden error (6fc519db)
    • Add .vertrektijden error test (b159081e)
    • Use test() alias instead of dotest.test() (81784da7)
    • Add config.timeout test (c9c558d2)
    • Run all tests even without user/pass (ad426f66)
  • script: No need to check for user/pass (e961140f)
  • config: Removed node v0.12 from Travis CI (1f88a049)
  • fix: Fixed eslint operator-linebreak before (bfe6d713)

2.0.1 (2016-5-29)

Chores
Documentation Changes
  • badges: Add npm version for changelog (13ee0c7d)
  • readme: Deeplink Gemnasium badge to dependencies tab (3a4c18c4)
Other Changes
  • undefined:
Tests
  • runner: Check credentials after basic tests (e03707af)