Search code examples
javascriptprotocol-buffersgtfs

Cannot read property 'decode' of undefined


I have been playing around with the General Transit Feed Specification - Realtime, and I am following exactly the example given on google's documentation:

https://developers.google.com/transit/gtfs-realtime/examples/nodejs-sample

for JavaScript, using my cities local transit feed, however I keep encountering the following error:

var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
                                            ^
TypeError: Cannot read property 'decode' of undefined

I have a working implementation in python that follows their example for that, so I can verify with certainty that the feed is the correct format.

I am running the code using the instruction:

node index.js

My package.json includes all the relevant dependencies, and I have installed using npm the required packages. I have searched far and wide for a solution to this error but have had no luck. Any advice?


Solution

  • Looking at the current example code on GitHub (https://github.com/MobilityData/gtfs-realtime-bindings/tree/master/nodejs#example-code) it seems you're missing transit_realtime in between:

    GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);