Socket
Socket
Sign inDemoInstall

ns-api

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ns-api

Public transit data from Nederlandse Spoorwegen API


Version published
Weekly downloads
11
increased by10%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

paramtypedefaultdescription
keystringOne of your API keys
[timeout]number8000Request 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.

parametertypedescription
[dateTime]Date or stringLimit 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

parametertypedescription
[lang]stringText 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.

parametertypedescription
[dateTime]Date or stringLimit 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.

parametertypedescription
[actual]booleanOnly 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

parametertypedescription
[dateTime]Date or stringLimit 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

parametertypedescription
typestringDisruption type
idstringDisruption object ID
ns.getDisruption ({
  type: 'maintenance',
  id: '7001000',
})
  .then (console.log)
  .catch (console.error)
;

API documentation

getTrips

Get a list of travel advises

parametertypedescription
[dateTime]Date or stringLimit 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

parametertypedescription
ctxReconstringTrip ctxRecon from getTrips()
ns.getTrip ({ ctxRecon: 'abc123' })
  .then (console.log)
  .catch (console.error)
;

API documentation

getPrice

Get pricing for travel between two stations.

parametertypedescription
fromStationstringStation name or ID
toStationstringStation 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.

parametertypedescription
idstringJourney 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.

argumenttypedescription
parametersobjectSee API docs
ns.placesList ({
  q: 'utrecht cs',
});

API documentation

placesGet

Get details about one place. Returns an object.

parametertypedescription
typestringPlace type, ex: stationV2
idstringPlace ID, ex: AMF
[lang]stringResponse language
ns.placesGet ({
  type: 'stationV2',
  id: 'AMF',
});

API documentation

placesOvfiets

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

parametertypedescription
[station_code]stringFilter 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

Keywords

FAQs

Last updated on 30 Aug 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc