loading
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var GtfsRealtimeBindings = require('gtfs-realtime-bindings');
var request = require('request');

const operator = "HSL";

var req = {
  url: 'https://api.digitransit.fi/realtime/trip-updates/v1/'+operator,
  method: 'GET',
  encoding: null
};

request(req, function (error, response, body) {
  if (!error && response.statusCode == 200) {
    var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
    feed.entity.forEach(function(entity) {
      //Print only trip updates
      if (entity.trip_update) {
        console.log(entity.trip_update.trip.trip_id+" (route: "+entity.trip_update.trip.route_id+"), delay: "+entity.trip_update.delay+"s");
      }
    });
  }
});
node v10.16.0