Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including node-trafikinfo with all npm packages installed. Try it out:

var nodeTrafikinfo = require("node-trafikinfo")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

node-trafikinfo v0.0.9

npm module for connecting to the swedish trafikinfo API

Node Trafikinfo

Utility for connecting to the Swedish transit api in node. Takes any options specified here and a callback.
Module is incomplete and untested please don't use

##Setup

npm install node-trafikinfo
var trafikClient = require('node-trafikinfo'),
    trafikinfo = new trafikClient('yourapikey');

Query departing train times

trafikinfo.get(
    {
        objectType: 'TrainAnnouncement',
        orderBy: 'ScheduledDepartureDateTime',
        filter: [
            { ActivityType: 'Avgang' },
            { LocationSignature: queryObj.from },
            { ToLocation: queryObj.to },
            { AdvertisedTimeAtLocation: ['-00:15:00','14:00:00'] }
        ],
        includes: [
            'AdvertisedTrainIdent',
            'ScheduledDepartureDateTime',
            'ToLocation'
        ]
    },
    function(data) {
        console.log(data)
    }
)

An example of querying all Train Station results:

trafikinfo.get(
    {
        objectType: 'TrainStation',
        includes: [
            'Prognosticated',
            'AdvertisedLocationName',
            'LocationSignature'
        ],
    },
    function(data) {
        console.log(data)
    }
)

An example of querying railway messages at a location:

trafikinfo.get(
    {
        objectType: 'TrainMessage',
        orderBy: 'AdvertisedTimeAtLocation',
        filter: [
            { AffectedLocation:'Cst' }
        ],
        includes: [
            'StartDateTime',
            'LastUpdateDateTime',
            'ExternalDescription',
            'ReasonCodeText'
        ]
    },
    function(data) {
        console.log(data)
    }
)

An example of querying a train's timetable:

trafikinfo.get(
    {
        objectType: 'TrainAnnouncement',
        filter: [
            { AdvertisedTrainIdent: '535' }
        ],
    },
    function(data) {
        console.log(data)
    }
)
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free