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

var req = {
  url: 'https://api.digitransit.fi/realtime/service-alerts/v1/',
  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 service alerts
      if (entity.alert) {
        console.log(JSON.stringify(entity.alert, null, 4));
      }
    });
  }
});
node v10.16.0