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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cta-api

v0.0.4

Published

Chicago Trainsit Authority (CTA) Api Wrapper

Readme

cta-api-node

Thin node wrapper for the Chicago Transit Authority API written in Node.js

Notes

I am new to node. My concentration was making this an extremely thin wrapper using only node core modules. As such, you will find no non-core dependencies. I also felt that testing would be over kill.

Responses are in XML. Take this up with Rahm.

Lots of juicy info for Chicago's developers here:

http://www.transitchicago.com/developers/

Complete list of 'L' Stops:

https://data.cityofchicago.org/Transportation/CTA-System-Information-List-of-L-Stops/8pix-ypme

Usage

Get the api keys from Chicago Trainsit above

$ export CTA_TRAIN_API_KEY=hunter2
$ export CTA_BUS_API_KEY=azureDiamond
$ node my_awesome.js
// my_awesome.js

var ctaNode = require("cta-api");

var trainApiKey = process.env.CTA_TRAIN_API_KEY
    , busApiKey = process.env.CTA_BUS_API_KEY;

ctaNode
  .train
  .arrivals
  .get({ mapid: 40360, max: 1, key: trainApiKey }, 
      function(data) { console.log("Data: " + data); },
      function(e) { console.log("Error: " + e.message); });

Trains

Official Train Tracker API:
http://www.transitchicago.com/developers/ttdocs/default.aspx

Locations

Parameters

Name | Value | Description ---- | ----- | ----------- mapid | Numeric station identifier (required if stpid not specified) | A single five-digit code to tell the server which station you’d like to receive predictions for. See appendix for information about valid station codes. stpid | Numeric stop identifier (required if mapid not specified) | A single five-digit code to tell the server which specific stop (in this context, specific platform or platform side within a larger station) you’d like to receive predictions for. See appendix for information about valid stop codes. max | Maximum results (optional) | The maximum number you’d like to receive (if not specified, all available results for the requested stop or station will be returned) rt | Route code (optional) | Allows you to specify a single route for which you’d like results (if not specified, all available results for the requested stop or station will be returned) key |Alphanumeric API key (required) |Your unique API key, assigned to you after agreeing to DLA and requesting a key be generated for you.

var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.train.arrivals.get({ mapid: 40360, max: 1, key: trainApiKey }, callback, errorCb)

Follow That Train

Parameters

Name | Value | Description ---- | ----- | ----------- runnumber | Train Run Number (required) | Allows you to specify a single run number for a train for which you’d like a series of upcoming arrival estimations. key | Alphanumeric API key (required) | Your unique API key, assigned to you after agreeing to DLA and requesting a key be generated for you.

var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.train.followThisTrain.get({ runnumber: 909, key: trainApiKey }, callback, errorCb)

Locations

Parameters

Name | Value | Description ---- | ----- | ----------- rt | Train route(s) (required) | Allows you to specify one or more routes for which you’d like train location information. key | Alphanumeric API key (required) | Your unique API key, assigned to you after agreeing to DLA and requesting a key be generated for you.

var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.train.locations.get({ rt: 'red', key: trainApiKey }, callback, errorCb)

Buses

Official Bus Tracker API:
http://www.transitchicago.com/assets/1/developer_center/BusTime_Developer_API_Guide.pdf

Time

Name | Value | Description ---- | ----- | ----------- Key | string (required) | 25-digit Bus Tracker API access key.

  ctaNode.bus.time.get({ key: busApiKey }, callback, errorCb);

Vehicles

Name | Value | Description ---- | ----- | ----------- Key | string (required) | 25-digit Bus Tracker API access key. Vid | comma-delimited list of vehicle IDs (not available with rt parameter) | Set of one or more vehicle IDs whose location should be returned. For example: 509,392,201,4367 will return information for four vehicles (if available). A maximum of 10 identifiers can be specified. Rt | comma-delimited list of route designators (not available with vid parameter) | Set of one or more route designators for which matching vehicles should be returned. For example: X3,4,20 will return information for all vehicles currently running those three routes (if available). A maximum of 10 identifiers can be specified.

  ctaNode.bus.vehicles.get({ key: busApiKey, vid: [509,392] }, callback, errorCb);
  ctaNode.bus.vehicles.get({ key: busApiKey, rt: [80] }, callback, errorCb);

Routes

Name | Value | Description ---- | ----- | ----------- Key | string (required) | 25-digit Bus Tracker API access key.

  ctaNode.bus.routes.get({ key: busApiKey }, callback, errorCb);

Route Directions

Name | Value | Description ---- | ----- | ----------- Key | string (required) | 25-digit Bus Tracker API access key. Rt | Single route designator (required) | Alphanumeric designator of a route (ex. “20” or “X20”) for which a list of available directions is to be returned.

  ctaNode.bus.routes.get({ key: busApiKey }, callback, errorCb);

Name | Value | Description ---- | ----- | ----------- key | string (required) | 25-digit Bus Tracker API access key. rt | Single route designator (required) | Alphanumeric designator of the route (ex. “20” or “X20”) for which a list of available stops is to be returned.

  ctaNode.bus.directions.get({ key: busApiKey, rt: 80 }, callback, errorCb);

Stops

Name | Value | Description ---- | ----- | ----------- key | string (required) | 25-digit Bus Tracker API access key. rt | Single route designator (required) | Alphanumeric designator of the route (ex. “20” or “X20”) for which a list of available stops is to be returned. dir | Single route direction (required) | Direction of the route (ex. “East Bound”) for which a list of available stops is to be returned.

  ctaNode.bus.stops.get({ key: busApiKey, rt: 80, dir: "Westbound" }, callback, errorCb);

Patterns

Name | Value | Description ---- | ----- | ----------- key | string (required) | 25-digit Bus Tracker API access key. pid | comma-delimited list of pattern IDs (not available with rt parameter) | Set of one or more pattern IDs whose points should be returned. For example: 56,436,1221 will return points from three (3) patterns. A maximum of 10 identifiers can be specified. rt | Single route designator (required) | Alphanumeric designator of the route (ex. “20” or “X20”) for which a list of available stops is to be returned.

  ctaNode.bus.patterns.get({ key: busApiKey, rt: 80, vid: 909, top: 5 }, callback, errorCb);

Predictions

Name | Value | Description ---- | ----- | ----------- key | string (required) | 25-digit Bus Tracker API access key. stpid | comma-delimited list of stop IDs (not available with vid parameter) | Set of one or more stop IDs whose predictions are to be returned. For example: 5029,1392,2019,4367 will return predictions for the four stops. A maximum of 10 identifiers can be specified. rt | comma-delimited list of route designators (optional, available with stpid parameter) | Set of one or more route designators for which matching predictions are to be returned. vid | comma-delimited list of vehicle IDs (not available with stpid parameter) | Set of one or more vehicle IDs whose predictions should be returned. For example: 509,392,201,4367 will return predictions for four vehicles. A maximum of 10 identifiers can be specified. top | number (optional) | Maximum number of predictions to be returned.

  ctaNode.bus.predictions.get({ key: busApiKey, rt: 20, stpid: 456 }, callback, errorCb);

Service Bulletins

Name | Value | Description ---- | ----- | ----------- key | string (required) | 25-digit Bus Tracker API access key. rt | comma-delimited list of route designators (optional, available with stpid parameter) | Set of one or more route designators for which matching predictions are to be returned. rtdir | Single route direction (optional) | Direction of travel of the route specified in the rt parameter. The rt parameter is required when using the rtdir parameter. stpid | comma-delimited list of stop IDs (not available with vid parameter) | Set of one or more stop IDs whose predictions are to be returned. For example: 5029,1392,2019,4367 will return predictions for the four stops. A maximum of 10 identifiers can be specified.

  ctaNode.bus.bulletins.get({ key: busApiKey, rt: 20, stpid: 456 }, callback, errorCb);

Alerts

Gives you information on stop/station outages and signifant alerts.

No options.
There appears to be HTML in some of the alerts. Take it up with Rahm.

var callback = function(data) { console.log("" + data); }
var errorCb = function(e) { console.log(e.message); }
ctaNode.customerAlerts.routeStatus.get({}, callback, errorCb);
ctaNode.customerAlerts.detailedAlerts.get({}, callback, errorCb);

Contribute

Fork, code, pull request