{"id":36542685,"url":"https://github.com/tgoulder4/trainspy","last_synced_at":"2026-01-12T05:49:18.255Z","repository":{"id":183512523,"uuid":"670285706","full_name":"tgoulder4/trainspy","owner":"tgoulder4","description":"trainspy - fast \u0026 free real-time train tracker","archived":false,"fork":false,"pushed_at":"2024-07-20T02:05:02.000Z","size":4552,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-26T21:23:00.683Z","etag":null,"topics":["train-station","train-status","train-tracker","trains","trains-information"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/trainspy","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tgoulder4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-07-24T17:48:15.000Z","updated_at":"2024-05-11T03:28:24.000Z","dependencies_parsed_at":"2023-07-24T18:58:46.621Z","dependency_job_id":"d93fa85b-c3b2-4055-b8ba-afb48f7d426e","html_url":"https://github.com/tgoulder4/trainspy","commit_stats":null,"previous_names":["tgoulder4/stationspy","tgoulder4/trainspy"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/tgoulder4/trainspy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgoulder4%2Ftrainspy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgoulder4%2Ftrainspy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgoulder4%2Ftrainspy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgoulder4%2Ftrainspy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tgoulder4","download_url":"https://codeload.github.com/tgoulder4/trainspy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tgoulder4%2Ftrainspy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28335319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["train-station","train-status","train-tracker","trains","trains-information"],"created_at":"2026-01-12T05:49:17.623Z","updated_at":"2026-01-12T05:49:18.246Z","avatar_url":"https://github.com/tgoulder4.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trainspy 🔍\n\n[![Downloads](https://img.shields.io/npm/dt/trainspy?logo=npm\u0026style=flat-square)](https://npmjs.com/package/trainspy) [![Discord](https://img.shields.io/discord/1128724355854114848?logo=discord\u0026logoColor=white\u0026style=flat-square)](https://discord.gg/3bnnkvrZwc)\n\nGet departures at any UK train station \u0026 recieve instant real-time updates on trains throughout their journey, without an API key. Version 2.0 brings exact location tracking with precise latitude \u0026 longitude co-ordinates!\n\n_Add me on discord - I'd love to hear your feedback! @thaitiesthetie_\n\n## Install trainspy\n\n```js\nnpm i trainspy\n```\n\n# Find departures\n\n`findTrains(stationNameOrCode)` _-\u003e Promise\\\u003ctypeof Object\u003e_\n\n```js\nimport { findTrains } from \"trainspy\";\n\n(async () =\u003e {\n  const trains = await findTrains(\"WLF\");\n  const moreTrains = await findTrains(\"Solihull\");\n\n  console.log(trains);\n})();\n```\n\nthis yields a response:\n\n```js\n{\n  name: 'Whittlesford Parkway',\n  code: 'WLF',\n  location: { latitude: 52.1035981209, longitude: 0.1656457011 },\n  departures: [\n    {\n      serviceID: 'L13825',\n      destination: 'Norwich',\n      arrival: { actual: '2109', scheduled: '2109' },\n      departure: { actual: '2109¼', scheduled: '2109' },\n      platform: '2',\n      stopsHere: true,\n      state: {\n        status: 'Passed',\n        station: {\n          name: 'Waterbeach',\n          code: 'WBC',\n          location: { latitude: 52.2623177182, longitude: 0.1968191721 },\n          platform: '2',\n          stopsHere: false,\n          delay: 0,\n          arrival: { actual: null, scheduled: null },\n          departure: { actual: '2127½', scheduled: '2128' }\n        }\n      }\n    },\n    ...]\n}\n```\n\n# Tracking a train\n\n`trackTrain(serviceID, date?, timeTillRefresh?)` _-\u003e Promise\\\u003ctypeof EventEmitter\u003e_\n\nEmit live updates on a train until its journey is complete. You first need the `serviceID`. Retrieved by `findTrains(stationNameOrCode)` as shown above.\n\nE.g. ServiceID `P70052` departing on 18/08/2023:\n\n```js\nimport { trackTrain } from \"trainspy\";\n\ntrackTrain(\"P70052\", \"2023-08-18\").then((emitter) =\u003e {\n  emitter.on(\"journey\", (update) =\u003e {\n    //your code for journey updates!\n  });\n  emitter.on(\"information\", (update) =\u003e {\n    console.log(update);\n  });\n});\n```\n\n_**🌻 Note**: Date must be in the form YYYY-MM-DD, defaults to today. You must enter an event name of \"journey\" for journey updates, and \"information\" for information (error, cancellation etc.) updates._\n\nExample journey update:\n\n```js\n{\n  status: 'At platform',\n  station: {\n    name: 'Smethwick Rolfe Street',\n    code: 'SMR',\n    location: { latitude: 52.4963984863, longitude: -1.9706383988 },\n    platform: '2',\n    stopsHere: true,\n    delay: 0,\n    arrival: { actual: '2146¾', scheduled: '2146½' },\n    departure: { actual: null, scheduled: '2147' }\n  },\n  callingPoints: [\n  {\n    name: 'Sandwell \u0026 Dudley',\n    code: 'SAD',\n    location: { latitude: 52.508672806, longitude: -2.0115900516 },\n    platform: '2',\n    stopsHere: true,\n    delay: 0,\n    arrival: { actual: null, scheduled: '2152' },\n    departure: { actual: null, scheduled: '2153' }\n  },\n    ...\n  ]\n}\n```\n\nExample information update:\n\n```js\n  {\n    information: 'Error', details: 'Check service ID.'\n  }\n```\n\n## Return values\n\nJourney updates\n\n| Property      | Type                                                                                                                                                                                                                                                                   |\n| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| status        | string                                                                                                                                                                                                                                                                 |\n| station       | { `name`: string, `code`: string \\| null, `location`: { `longitude`: number \\| null, `latitude`: number \\| null }`stopsHere`: boolean, `delay`: number \\| null, `arrival`: { `actual`: string \\| null, `scheduled`: string \\| null }, `departure`: -same as arrival- } |\n| callingPoints | Array\\\u003cstation\u003e                                                                                                                                                                                                                                                        |\n\nInformation updates\n| Property | Type |\n| ------------- | ---------------------------- |\n| information | string |\n| details | string |\n\nStatuses\n\n| Status      | Explanation                                         |\n| ----------- | --------------------------------------------------- |\n| Passed      | Train just passed this non-stopping station         |\n| Approaching | Train is now approaching this station               |\n| Arriving    | Train is now arriving at this stopping station      |\n| At platform | Train is now at a platform of this stopping station |\n| Departed    | Train just departed this stopping station           |\n\n## More examples\n\nTrack the next service from London to Manchester, today:\n\n```js\nimport { trackTrain, findTrains } from \"trainspy\";\n\nconst response = await findTrains(\"EUS\");\nconst serviceID = response.departures.find(\n  (departure) =\u003e departure.destination == \"Manchester Piccadilly\"\n).serviceID;\ntrackTrain(serviceID).then((emitter) =\u003e {\n  emitter.on(\"journey\", (update) =\u003e {\n    //do stuff!\n  });\n});\n```\n\nBasic react implementation\n\n```js\nimport {trackTrain} from \"trainspy\";\n\nclass trainInformationComponent extends Component {\n  state = {\n    Status: '',\n    Station:''\n  };\n\n  trackTrain(\"P56592\").then(emitter=\u003e{\n    emitter.on(\"journey\",(update)=\u003e{\n      handleInfoChange(update);\n    })\n  });\n\n  handleInfoChange = (newData) =\u003e {\n    const newStatus = newData.status;\n    const newStation = newData.station.name;\n    this.setState({\n      Status: newStatus,\n      Station: newStation\n    });\n  }\n\n  render() {\n    return (\n      \u003c\u003e\n      \u003ctitle\u003eTracking service P56592\u003c/title\u003e\n      \u003clabel\u003eStatus: {state.Status}\u003c/label\u003e\n      \u003clabel\u003eStation: {state.Station}\u003c/label\u003e\n      \u003c/\u003e\n    );\n  }\n};\n```\n\nA project by Tye.\nSpecial thanks to @ellcom for their list of longitude \u0026 latitude for each station, and to RealTimeTrains for providing the primitives for this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftgoulder4%2Ftrainspy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftgoulder4%2Ftrainspy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftgoulder4%2Ftrainspy/lists"}