Newbie Paintball Master

    gtfs-realtime
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.1 • Public • Published

    ➡️ Installation | Quick Start ⬅️

    node-GTFS-Realtime



    Download GTFS-Realtime data as JSON

    NPM


    GTFS-realtime transit data is in protobuf format which means its not human-readable by default. node-GTFS-Realtime aims to make it fast and easy to inspect GTFS-realtime data by providing a one-line command for downloading GTFS-realtime format data and converting to JSON.

    Run it right now from your command line:

    npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx
    

    The command above will fetch BART's GTFS-Realtime trip updates and save them to a file to the current directory in JSON format, named like gtfs-realtime-2022-05-28T002330.164Z.json (using the current time). You can open the resulting file in a text editor to review.

    node-GTFS-Realtime can be used as a command-line tool or as a node.js module.

    Example JSON

    Below is an example of the JSON result for a GTFS-Realtime Trip Updates request:

    {
      "header": {
        "gtfsRealtimeVersion": "1.0",
        "incrementality": "FULL_DATASET",
        "timestamp": "1653701655"
      },
      "entity": [
        {
          "id": "1001663",
          "tripUpdate": {
            "trip": {
              "tripId": "1001663",
              "scheduleRelationship": "SCHEDULED"
            },
            "stopTimeUpdate": [
              {
                "stopSequence": 13,
                "arrival": {
                  "delay": 25,
                  "time": "1653701754",
                  "uncertainty": 30
                },
                "departure": {
                  "delay": 25,
                  "time": "1653701775",
                  "uncertainty": 30
                },
                "stopId": "SANL"
              }
            ]
          }
        }
      ]
    }

    Installation

    If you would like to use this library as a command-line utility, you can install it globally directly from npm:

    npm install gtfs-realtime -g
    

    Or you can use it directly via npx:

    npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx
    

    If you are using this as a node module as part of an application, you can include it in your project's package.json file.

    Quick Start

    Command-Line Examples

    Run via npx:

    npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx
    

    If installed globally:

    gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx
    

    With custom HTTP headers

    gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --header "Authorization: bearer 1234567"
    

    Code example

    import gtfsRealtime from 'gtfs';
    
    const config = {
      url: 'http://api.bart.gov/gtfsrt/tripupdate.aspx',
      output: '/path/to/save/file.json',
      header: ['Authorization: bearer 12345'],
    };
    
    gtfsRealtime(config)
      .then(() => {
        console.log('Import Successful');
      })
      .catch((err) => {
        console.error(err);
      });

    Command-Line Usage

    gtfs-realtime [options...] <url>
    
    The `gtfs-realtime` command-line utility will download GTFS-Realtime data from the specified URL and save it as a JSON file.
    
    ### Options
    
    `-s, --silent`
    
    Hides all console output
    
        gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --silent
    
    `-H, --header`
    
    Specify one or more HTTP headers to be included in the request.
    
        gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --header "Authorization: bearer 1234567" --header "test:true"
    
    `-o, --output`
    
    Specify a path to save the JSON file. Optional, defaults to the current directory using a filename with the current time.
    
        gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --output /path/to/save/file.json
    
    `--help`
    
    Show help.
    
        gtfs-realtime --help
    
    `--version`
    
    Show version
    
        gtfs-realtime --version
    
    ## Contributing
    
    Pull requests are welcome, as is feedback and [reporting issues](https://github.com/blinktaginc/node-gtfs-realtime/issues).
    
    ### Linting
    
        npm run lint
    

    Install

    npm i gtfs-realtime

    DownloadsWeekly Downloads

    3

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    23 kB

    Total Files

    14

    Last publish

    Collaborators

    • brendannee