Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

360
Views
Output data got from external API on express get request

From the example code on the gtfs-realtime-bindings library's documentaion,
I tried to put similar logic inside my router but was not able to take the result out of request()

route.get('/', (req, res) => {
  const data = [];
  request(requestSettings, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      const feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body);
      feed.entity.forEach(function(entity) {
        if (entity.tripUpdate) {
          data.push(entity.tripUpdate);
        }
      });
    }
  res.status(200).json( data );
}); // empty array returns

Then I tried to use axios, but decode() raise "Error: illegal buffer"

const realtimeRequest = () => {
  axios.get('https://opendata.hamilton.ca/GTFS-RT/GTFS_TripUpdates.pb')
  .then(function (body) {
    const feed = GtfsRealtimeBindings.transit_realtime.FeedMessage.decode(body.data);
    // body.data looks like this '\x03436\x12\x041219 ����\x06'
    return feed;
  }).catch(error => console.log(error));
}

route.get('/', (req, res) => {
  realtimeRequest()
  .then(() => {
    res.status(200).json( data );
  })
}
/**
Error: illegal buffer
    at create_typed_array (/node_modules/protobufjs/src/reader.js:47:15)
    at create_buffer (/node_modules/protobufjs/src/reader.js:69:19)
    at Function.create_buffer_setup (/node_modules/protobufjs/src/reader.js:70:11)
    at Function.decode (/node_modules/gtfs-realtime-bindings/gtfs-realtime.js:134:34) **/
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!