This guide walks you through fetching real-time subway arrivals for a specific stop and route. You will initialize theDocumentation Index
Fetch the complete documentation index at: https://mtaapi.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
MTA client, call mta.subway.arrivals(), and process the response to display upcoming trains in your application.
Prerequisites
mta-jsinstalled in your project (npm install mta-js)- An MTA API key set as
MTA_API_KEYin your environment
Find your stop ID
Every MTA subway stop has a unique stop ID. Stop IDs follow a letter-and-number format where the letter generally corresponds to the train line complex and the number identifies the specific station.A few examples to get you oriented:
You can look up stop IDs in the MTA GTFS Static Data or reference the
| Stop ID | Station |
|---|---|
A27 | Howard Beach–JFK Airport (A train) |
R16 | Times Square–42 St (N/Q/R trains) |
120 | 96 St (1/2/3 trains) |
D14 | Atlantic Av–Barclays Ctr (B/D/N/Q trains) |
stops.txt file in the MTA’s GTFS feed. Pass the stop ID as a string exactly as it appears in those resources.Call mta.subway.arrivals()
Import the Both
MTA client and call mta.subway.arrivals() with the stopId and route you want to query.stopId and route are required. The route value is the train letter or number as it appears on signage (e.g., 'A', '1', 'N', 'L').Process the response
The response is an array of Use
Arrival objects. Each entry includes the route and stop as structured objects, the predicted arrival time as an ISO 8601 string, a minutes field pre-computed for you, and optional destination / displayDirection fields for building human-readable UI.displayDirection first (e.g. "toward 8 Av"), falling back to destination (the raw headsign), and finally the raw direction string.Example response:Complete example
The function below ties all the steps together into a reusable arrivals display function.The
direction field uses NYCT’s 'north' / 'south' values even on east-west lines. For the L train, mta-js also accepts rider-facing 'east' / 'west' aliases as query input and maps them to the underlying feed directions. For display, prefer displayDirection (e.g. "toward 8 Av") or destination over the raw direction string.