Train Times API
This API is a wrapper around the MTA's GTFS specification. You can use it to:
- Find the next trains coming to your station
- Get a JSON object mapping train lines to their corresponding MTA feed id's.
- Get a JSON object with relevant information for all MTA stops.
This is a project built by Mari and Patrick.
Set up the project
- Clone the repo
git clone https://github.com/mgalicer/train-times.git
cd train-times/
npm install
-
Register for an API key on the MTA's website
-
Add your API key to the script
touch .env
echo "MTA_KEY=MY_MTA_KEY" >> .env
- Add the port you want to use to develop locally
echo "PORT=3000" >> .env
- Run the API
npm start
Example endpoint:
Find the next train times for a given stop
Say we're looking for the next A train times going south at Jay St. MetroTech. You can either go to http://localhost:3000/stops
and look for your stop, or check out the stops.csv. At Jay St., the stop id is A41.
Next, pass the train line, stop id, and direction into the API:
localhost:3000/next-train-times/A/A41/S
You should receive an array with the upcoming train arrival times.
[8,14,22,32,45,55,65,75]
Get a JSON object with select information for all stops
localhost:3000/stops
Get a JSON object with feed ids for all train lines
localhost:3000/line-to-feed-ids
The returned object has keys that are train lines, ex C
, and values that are an MTA feed ID, ex 26