Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49186

How to use a package after npm install

$
0
0

@Leetcat wrote:

I want to use the node package "gtfs-realtime-bindings" in my ionic project.
You can find it here: https://www.npmjs.com/package/gtfs-realtime-bindings

But once I do npm install gtfs-realtime-bindings then I add the example code into one of my controllers:

angular.module('app.controllers', [])
  .controller('MapCtrl', function($scope, $state) {
    var GtfsRealtimeBindings = require('gtfs-realtime-bindings');
    var request = require('request');

    var requestSettings = {
      method: 'GET',
      url: 'URL OF YOUR GTFS-REALTIME SOURCE GOES HERE',
      encoding: null
    };
    request(requestSettings, function (error, response, body) {
      if (!error && response.statusCode == 200) {
        var feed = GtfsRealtimeBindings.FeedMessage.decode(body);
        feed.entity.forEach(function(entity) {
          if (entity.trip_update) {
            console.log(entity.trip_update);
          }
        });
      }
    });
  });

I get the error.. Error: Can't find variable: require.

What other js code needs to be added?

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49186

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>