NYC subway realtime feeds describe trains by NYCT’sDocumentation Index
Fetch the complete documentation index at: https://mtaapi.dev/docs/llms.txt
Use this file to discover all available pages before exploring further.
north / south direction — even on east–west lines like the L. But riders don’t think in compass directions; they think “I’m trying to get to Union Sq.” This guide shows you how to use mta.subway.direction() to translate a destination string into the feed direction, then use that direction to fetch the right arrivals.
mta.subway.direction() requires a hosted apiKey. It resolves destinations against the hosted API’s static GTFS route order and is not available in direct-feed mode. See Authentication to get a key.Prerequisites
mta-jsinstalled (npm install mta-js)- An MTA API key set as
MTA_API_KEYin your environment
Resolve a destination to a direction
Call All three parameters are required:
mta.subway.direction() with the route the rider is on, the fromStopId they’re departing from, and the destination they typed. The method resolves the destination against the route’s stop order and returns the north / south direction that heads toward it.| Parameter | Type | Description |
|---|---|---|
route | string | The subway route the rider is traveling on (e.g. 'L'). |
fromStopId | string | The stop the rider is departing from (e.g. 'L08' for Bedford Av). |
destination | string | A rider-facing destination to resolve (e.g. 'Union Sq'). Matching tolerates casing and common station-name variations. |
Branch on the result
The method always resolves to a When
SubwayDirectionResolution object — it never returns null. Check the resolved flag before reading the direction.resolved is true, the direction, displayDirection, terminal, and destinationStop fields are populated. When it’s false, reason explains why, and matches may contain ambiguous candidate stops you can disambiguate in your UI.Complete example
This helper takes a rider’s origin, route, and destination and returns the next trains heading the right way — or a helpful message when the destination can’t be resolved.Example resolution
Handling ambiguous or unresolved destinations
When a destination string matches more than one stop — or none —resolved is false. Use reason for a short explanation and matches to offer the rider a choice.
Subway feed directions are always
north / south, even on east–west lines like the L. mta.subway.direction() resolves to one of those two values so it can be passed directly to mta.subway.arrivals(). For the full parameter and type reference, see the Direction API reference.