A comprehensive Node.js/TypeScript API server that provides real-time BC Transit information using GTFS static and GTFS-realtime feeds.
- Bus Arrivals: Get next arrival times for any stop
- Nearby Stops: Find transit stops near a location
- Vehicle Positions: Real-time bus locations and status
- Service Alerts: Current service disruptions and notifications
- Routes & Stops: Complete route and stop information
- Trip Details: Detailed trip information with stop sequences
# Install dependencies
npm install
# or
bun installCreate a .env file (optional):
PORT=3000
GTFS_REALTIME_URL=https://bct.tmix.se/gtfs-realtime/tripupdates.pb?operatorIds=48
GTFS_STATIC_URL=https://bct.tmix.se/Tmix.Cap.TdExport.WebApi/gtfs/?operatorIds=48# Development mode
npm run dev
# or
bun run dev
# Production build
npm run build
npm startThe server will start at http://localhost:3000 and automatically load GTFS data.
http://localhost:3000/api
GET /api
Returns complete API documentation and available endpoints.
GET /api/health
Returns server health status and uptime.
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"status": "healthy",
"uptime": 3600.5,
"version": "1.0.0"
}
}GET /api/arrivals/:stopId
GET /api/arrivals/:stopId?routeId={routeId}&max={maxArrivals}
GET /api/arrivals/:stopId/route/:routeId
GET /api/arrivals/:stopId/route/:routeId/next
Get live bus arrivals with real-time updates, delays, and status information.
Parameters:
stopId(path): The stop ID to get arrivals forrouteId(query/path): Filter by specific routemax(query): Maximum arrivals to return (default: 5)
Live Features:
- ⚡ Real-time predictions with delays and uncertainties
- 🕐 Minutes until arrival with live countdown
- 📡 Live vs scheduled data indicators
⚠️ Status updates ("Arriving", "Due", "5 min", "Delayed")- 🎯 Route filtering for specific lines
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"stopId": "12345",
"arrivalCount": 2,
"arrivals": [
{
"stopId": "12345",
"routeId": "1",
"routeShortName": "1",
"routeLongName": "University/Downtown",
"routeColor": "FF0000",
"routeTextColor": "FFFFFF",
"tripHeadsign": "University",
"arrivalTimes": [
{
"time": 1642248600,
"headsign": "University",
"minutesUntilArrival": 3,
"delaySeconds": 120,
"isRealTime": true,
"uncertainty": 30,
"status": "3 min"
}
]
}
],
"isLiveData": true,
"lastUpdated": "2024-01-15T10:30:00.000Z"
}
}GET /api/stops/nearby?lat={latitude}&lon={longitude}&radius={meters}
Find transit stops near a location.
Query Parameters:
lat(required): Latitude (-90 to 90)lon(required): Longitude (-180 to 180)radius(optional): Search radius in meters (default: 500)
Example:
GET /api/stops/nearby?lat=48.4284&lon=-123.3656&radius=1000
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"location": {
"latitude": 48.4284,
"longitude": -123.3656
},
"radius": 1000,
"stopCount": 5,
"stops": [
{
"stop": {
"stopId": "12345",
"stopName": "Government & Belleville",
"stopLat": 48.4285,
"stopLon": -123.3655,
"stopCode": "12345"
},
"distance": 15
}
]
}
}GET /api/stops/:stopId
Get detailed information about a specific stop.
Parameters:
stopId(path): The stop ID
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"stopId": "12345",
"stopName": "Government & Belleville",
"stopDesc": "Government St at Belleville St",
"stopLat": 48.4285,
"stopLon": -123.3655,
"stopCode": "12345"
}
}GET /api/vehicles
GET /api/vehicles?routeId={routeId}
GET /api/vehicles/route/:routeId
Get real-time vehicle positions, optionally filtered by route.
Query Parameters:
routeId(optional): Filter vehicles by route ID
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"vehicleCount": 2,
"vehicles": [
{
"vehicleId": "1234",
"routeId": "1",
"tripId": "trip_123",
"latitude": 48.4284,
"longitude": -123.3656,
"bearing": 180.5,
"speed": 25.5,
"timestamp": 1642248600,
"occupancyStatus": "FEW_SEATS_AVAILABLE",
"congestionLevel": "RUNNING_SMOOTHLY"
}
]
}
}GET /api/alerts
GET /api/alerts?routeId={routeId}
GET /api/alerts?stopId={stopId}
Get service alerts and disruptions, optionally filtered by route or stop.
Query Parameters:
routeId(optional): Filter alerts by route IDstopId(optional): Filter alerts by stop ID
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"alertCount": 1,
"alerts": [
{
"alertId": "alert_123",
"headerText": "Route 1 Delay",
"descriptionText": "Route 1 is experiencing delays due to traffic",
"severity": "WARNING",
"effect": "SIGNIFICANT_DELAYS",
"activePeriods": [
{
"start": 1642248000,
"end": 1642251600
}
],
"informedEntities": [
{
"routeId": "1"
}
]
}
]
}
}GET /api/routes
GET /api/routes?page={page}&limit={limit}
Get all available routes with pagination.
Query Parameters:
page(optional): Page number (default: 1)limit(optional): Items per page (default: 50)
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": [
{
"routeId": "1",
"shortName": "1",
"longName": "University/Downtown",
"routeColor": "FF0000",
"routeTextColor": "FFFFFF"
}
],
"pagination": {
"page": 1,
"limit": 50,
"total": 100,
"hasNext": true,
"hasPrev": false
}
}GET /api/routes/:routeId
Get detailed information about a specific route.
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"routeId": "1",
"shortName": "1",
"longName": "University/Downtown",
"routeColor": "FF0000",
"routeTextColor": "FFFFFF"
}
}GET /api/routes/:routeId/stops
Get all stops served by a specific route.
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"route": {
"routeId": "1",
"shortName": "1",
"longName": "University/Downtown",
"routeColor": "FF0000",
"routeTextColor": "FFFFFF"
},
"stopCount": 25,
"stops": [
{
"stopId": "12345",
"stopName": "Government & Belleville",
"stopLat": 48.4285,
"stopLon": -123.3655,
"stopCode": "12345"
}
]
}
}GET /api/trips/:tripId
Get detailed information about a specific trip.
Response:
{
"success": true,
"timestamp": "2024-01-15T10:30:00.000Z",
"data": {
"trip": {
"tripId": "trip_123",
"routeId": "1",
"tripHeadsign": "University"
},
"route": {
"routeId": "1",
"shortName": "1",
"longName": "University/Downtown",
"routeColor": "FF0000",
"routeTextColor": "FFFFFF"
},
"stopTimes": [
{
"tripId": "trip_123",
"arrivalTime": "08:00:00",
"departureTime": "08:00:00",
"stopId": "12345",
"stopSequence": 1
}
]
}
}All endpoints return errors in a consistent format:
{
"success": false,
"timestamp": "2024-01-15T10:30:00.000Z",
"error": "Error message",
"errorDetails": "Detailed error information"
}Common HTTP status codes:
400- Bad Request (invalid parameters)404- Not Found (resource doesn't exist)500- Internal Server Error
This API uses BC Transit's GTFS feeds:
- Static GTFS: Route, stop, and schedule information
- GTFS-Realtime: Live vehicle positions, trip updates, and service alerts
src/
├── index.ts # Main server file
├── services/
│ └── gtfsService.ts # GTFS data management
├── types/
│ └── gtfs.ts # TypeScript interfaces
└── utils/
└── api.ts # API utilities
- Add new types to
src/types/gtfs.ts - Implement business logic in
src/services/gtfsService.ts - Add endpoint handlers to
src/index.ts - Update this documentation
npm run buildBuilds TypeScript to dist/ directory.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues and questions, please open a GitHub issue.