npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gtfs-realtime

v0.2.0

Published

Fetch GTFS Realtime data and convert to JSON

Downloads

28

Readme

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