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.
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
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:
You should receive an array with the upcoming train arrival times.
Get a JSON object with select information for all stops
Get a JSON object with feed ids for all train lines
The returned object has keys that are train lines, ex
C, and values that are an MTA feed ID, ex