{"id":13723853,"url":"https://github.com/BlinkTagInc/node-gtfs","last_synced_at":"2025-05-07T17:31:30.684Z","repository":{"id":2460360,"uuid":"3432328","full_name":"BlinkTagInc/node-gtfs","owner":"BlinkTagInc","description":"Import GTFS transit data into SQLite and query routes, stops, times, fares and more.","archived":false,"fork":false,"pushed_at":"2025-04-23T23:15:32.000Z","size":3528,"stargazers_count":458,"open_issues_count":7,"forks_count":151,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-05-05T18:39:08.355Z","etag":null,"topics":["geojson","gtfs","node-gtfs","public-transportation","sqlite","transit","transit-data"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlinkTagInc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-02-13T17:38:00.000Z","updated_at":"2025-05-02T16:58:59.000Z","dependencies_parsed_at":"2024-04-10T15:02:06.785Z","dependency_job_id":"51c60e2d-42a0-44e6-b0a0-dcb18c02eb24","html_url":"https://github.com/BlinkTagInc/node-gtfs","commit_stats":{"total_commits":863,"total_committers":52,"mean_commits":"16.596153846153847","dds":"0.11239860950173808","last_synced_commit":"d4e0157c7e54b4b17a80ac555f4b8e26e362d917"},"previous_names":["brendannee/node-gtfs"],"tags_count":170,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlinkTagInc%2Fnode-gtfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlinkTagInc%2Fnode-gtfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlinkTagInc%2Fnode-gtfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlinkTagInc%2Fnode-gtfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlinkTagInc","download_url":"https://codeload.github.com/BlinkTagInc/node-gtfs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252752042,"owners_count":21798722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["geojson","gtfs","node-gtfs","public-transportation","sqlite","transit","transit-data"],"created_at":"2024-08-03T01:01:46.343Z","updated_at":"2025-05-07T17:31:30.659Z","avatar_url":"https://github.com/BlinkTagInc.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  ➡️\n  \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e |\n  \u003ca href=\"#quick-start\"\u003eQuick Start\u003c/a\u003e |\n  \u003ca href=\"#typescript-support\"\u003eTypeScript Support\u003c/a\u003e |\n  \u003ca href=\"#configuration\"\u003eConfiguration\u003c/a\u003e |\n  \u003ca href=\"#query-methods\"\u003eQuery Methods\u003c/a\u003e\n  ⬅️\n  \u003cbr /\u003e\u003cbr /\u003e\n  \u003cimg src=\"docs/images/node-gtfs-logo.svg\" alt=\"node-GTFS\" /\u003e\n  \u003cbr /\u003e\u003cbr /\u003e\n  \u003ca href=\"https://www.npmjs.com/package/gtfs\" rel=\"nofollow\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/gtfs.svg?style=flat\" style=\"max-width: 100%;\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/gtfs\" rel=\"nofollow\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/gtfs.svg?style=flat\" style=\"max-width: 100%;\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/BlinkTagInc/node-gtfs/actions?query=workflow%3A%22Node+CI%22\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/BlinkTagInc/node-gtfs/nodejs.yml?branch=master\" style=\"max-width: 100%;\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"\u003e\n  \u003cbr /\u003e\u003cbr /\u003e\n  Import and Export GTFS transit data into SQLite. Query or change routes, stops, times, fares and more.\n  \u003cbr /\u003e\u003cbr /\u003e\n  \u003ca href=\"https://nodei.co/npm/gtfs/\" rel=\"nofollow\"\u003e\u003cimg src=\"https://nodei.co/npm/gtfs.png?downloads=true\" alt=\"NPM\" style=\"max-width: 100%;\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003chr\u003e\n\n`node-GTFS` loads transit data in [GTFS format](https://developers.google.com/transit/) into a SQLite database and provides some methods to query for agencies, routes, stops, times, fares, calendars and other GTFS data. It also offers spatial queries to find nearby stops, routes and agencies and can convert stops and shapes to geoJSON format. Additionally, this library can export data from the SQLite database back into GTFS (csv) format.\n\nThe library also supports importing GTFS-Realtime data into the same database. In order to keep the realtime database fresh, it uses `SQLITE REPLACE` which makes it very effective.\n\nYou can use it as a [command-line tool](#command-line-examples) or as a [node.js module](#code-example).\n\nThis library has four parts: the [GTFS import script](#gtfs-import-script), [GTFS export script](#gtfs-export-script) and [GTFS-Realtime update script](#gtfsrealtime-update-script) and the [query methods](#query-methods)\n\n## Installation\n\nTo use this library as a command-line utility, install it globally with [npm](https://npmjs.org):\n\n    npm install gtfs -g\n\nThis will add the `gtfs-import` and `gtfs-export` scripts to your path.\n\nIf you are using this as a node module as part of an application, include it in your project's `package.json` file.\n\n    npm install gtfs\n\n## Quick Start\n\n### Command-line examples\n\n    gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip\n\nor\n\n    gtfs-import --gtfsPath /path/to/your/gtfs.zip\n\nor\n\n    gtfs-import --gtfsPath /path/to/your/unzipped/gtfs\n\nor\n\n    gtfs-import --configPath /path/to/your/custom-config.json\n\n    gtfs-export --configPath /path/to/your/custom-config.json\n\n### Code example\n\n```js\nimport { importGtfs } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\n\ntry {\n  await importGtfs(config);\n} catch (error) {\n  console.error(error);\n}\n```\n\n### Example Applications\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/BlinkTagInc/gtfs-to-html/raw/master/www/static/img/gtfs-to-html-logo.svg\" alt=\"GTFS-to-HTML\" width=\"200\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://gtfstohtml.com\"\u003eGTFS-to-HTML\u003c/a\u003e uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library and is used by over a dozen transit agencies to generate the timetables on their websites.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/BlinkTagInc/gtfs-to-geojson/raw/master/docs/images/gtfs-to-geojson-logo.svg\" alt=\"GTFS-to-geojson\" width=\"200\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/blinktaginc/gtfs-to-geojson\"\u003eGTFS-to-geojson\u003c/a\u003e creates geoJSON files for transit routes for use in mapping. It uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/BlinkTagInc/gtfs-to-chart/raw/master/docs/images/gtfs-to-chart-logo.svg\" alt=\"GTFS-to-Chart\" width=\"200\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/blinktaginc/gtfs-to-chart\"\u003eGTFS-to-chart\u003c/a\u003e generates a stringline chart in D3 for all trips for a specific route using data from an agency's GTFS. It uses `node-gtfs` for downloading, importing and querying GTFS data.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/BlinkTagInc/gtfs-accessibility-validator/raw/main/docs/images/gtfs-accessibility-validator-logo.svg\" alt=\"GTFS Accessibility Validator\" width=\"200\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/blinktaginc/gtfs-accessibility-validator\"\u003eGTFS Accessibility Validator\u003c/a\u003e checks for accessiblity-realted fields and files and flags any issues. It uses `node-gtfs` for downloading, importing and querying GTFS data.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/BlinkTagInc/gtfs-tts/raw/main/docs/images/gtfs-tts-logo.svg\" alt=\"GTFS-TTS\" width=\"200\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/blinktaginc/gtfs-tts\"\u003eGTFS-Text-to-Speech\u003c/a\u003e app tests GTFS stop name pronunciation for text-to-speech. It uses `node-gtfs` for loading stop names from GTFS data.\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://raw.githubusercontent.com/BlinkTagInc/transit-departures-widget/main/docs/images/transit-departures-widget-logo.svg\" alt=\"Transit Departures Widget\" width=\"200\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ca href=\"https://github.com/BlinkTagInc/transit-departures-widget\"\u003eTransit Departures Widget\u003c/a\u003e creates a realtime transit departures widget from GTFS and GTFS-Realtime data.\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Command-Line Usage\n\nThe `gtfs-import` command-line utility will import GTFS into SQLite3.\n\nThe `gtfs-export` command-line utility will create GTFS from data previously imported into SQLite3.\n\n### gtfs-import Command-Line options\n\n`configPath`\n\nAllows specifying a path to a configuration json file. By default, `node-gtfs` will look for a `config.json` file in the directory it is being run from. Using a config.json file allows you specify more options than CLI arguments alone - see below.\n\n    gtfs-import --configPath /path/to/your/custom-config.json\n\n`gtfsPath`\n\nSpecify a local path to GTFS, either zipped or unzipped.\n\n    gtfs-import --gtfsPath /path/to/your/gtfs.zip\n\nor\n\n    gtfs-import --gtfsPath /path/to/your/unzipped/gtfs\n\n`gtfsUrl`\n\nSpecify a URL to a zipped GTFS file.\n\n    gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip\n\n## TypeScript Support\n\nBasic TypeScript typings are included with this library. Please [open an issue](https://github.com/blinktaginc/node-gtfs/issues) if you find any inconsistencies between the declared types and underlying code.\n\n## Configuration\n\nCopy `config-sample.json` to `config.json` and then add your projects configuration to `config.json`.\n\n    cp config-sample.json config.json\n\n| option                                                            | type              | description                                                                                                                                                         |\n| ----------------------------------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| [`agencies`](#agencies)                                           | array             | An array of GTFS files to be imported, and which files to exclude.                                                                                                  |\n| [`csvOptions`](#csvOptions)                                       | object            | Options passed to `csv-parse` for parsing GTFS CSV files. Optional.                                                                                                 |\n| [`db`](#db)                                                       | database instance | An existing database instance to use instead of relying on node-gtfs to connect. Optional.                                                                          |\n| [`downloadTimeout`](#downloadtimeout)                             | integer           | The number of milliseconds to wait before throwing an error when downloading GTFS. Optional.                                                                        |\n| [`exportPath`](#exportPath)                                       | string            | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/\u003cagency_name\u003e`.                                                                |\n| [`gtfsRealtimeExpirationSeconds`](#gtfsrealtimeexpirationseconds) | integer           | Amount of time in seconds to allow GTFS-Realtime data to be stored in database before allowing to be deleted. Optional, defaults to 0.                              |\n| [`ignoreDuplicates`](#ignoreduplicates)                           | boolean           | Whether or not to ignore unique constraints on ids when importing GTFS, such as `trip_id`, `calendar_id`. Optional, defaults to false.                              |\n| [`ignoreErrors`](#ignoreerrors)                                   | boolean           | Whether or not to ignore errors during the import process. If true, when importing multiple agencies, failed agencies will be skipped. Optional, defaults to false. |\n| [`sqlitePath`](#sqlitePath)                                       | string            | A path to an SQLite database. Optional, defaults to using an in-memory database.                                                                                    |\n| [`verbose`](#verbose)                                             | boolean           | Whether or not to print output to the console. Optional, defaults to true.                                                                                          |\n\n### agencies\n\n{Array} Specify the GTFS files to be imported in an `agencies` array. GTFS files can be imported via a `url` or a local `path`.\n\nFor GTFS files that contain more than one agency, you only need to list each GTFS file once in the `agencies` array, not once per agency that it contains.\n\n#### agencies options\n\n| option                     | type   | description                                                                                                                                                         |\n| -------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `url`                      | string | The URL to a zipped GTFS file. Required if `path` not present.                                                                                                      |\n| `path`                     | string | A path to a zipped GTFS file or a directory of unzipped .txt files. Required if `url` is not present.                                                               |\n| `headers`                  | object | An object of HTTP headers in key:value format to use when fetching GTFS from the `url` specified. Optional.                                                         |\n| `prefix`                   | string | A prefix to be added to every ID field maintain uniqueness when importing multiple GTFS from multiple agencies. Optional.                                           |\n| `exclude`                  | array  | An array of GTFS file names (without `.txt`) to exclude when importing. Optional.                                                                                   |\n| `realtimeAlerts`           | object | An object containing a `url` field for GTFS-Realtime alerts and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional.            |\n| `realtimeTripUpdates`      | object | An object containing a `url` field for GTFS-Realtime trip updates and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional.      |\n| `realtimeVehiclePositions` | object | An object containing a `url` field for GTFS-Realtime vehicle positions and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |\n\n- Specify a `url` to download GTFS:\n\n```json\n{\n  \"agencies\": [\n    {\n      \"url\": \"https://www.bart.gov/dev/schedules/google_transit.zip\"\n    }\n  ]\n}\n```\n\n- Specify a download URL with custom headers using the `headers` field:\n\n```json\n{\n  \"agencies\": [\n    {\n      \"url\": \"https://www.bart.gov/dev/schedules/google_transit.zip\",\n      \"headers\": {\n        \"Content-Type\": \"application/json\",\n        \"Authorization\": \"bearer 1234567890\"\n      }\n    }\n  ]\n}\n```\n\n- Specify a `path` to a zipped GTFS file:\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/gtfs.zip\"\n    }\n  ]\n}\n```\n\n- Specify a `path` to an unzipped GTFS file:\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\"\n    }\n  ]\n}\n```\n\n- If you don't want all GTFS files to be imported, you can specify an array of files to `exclude`. This can save a lot of time for larger GTFS.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\",\n      \"exclude\": [\"shapes\", \"stops\"]\n    }\n  ]\n}\n```\n\n- Specify urls for GTFS-Realtime updates. `realtimeAlerts`, `realtimeTripUpdates` and `realtimeVehiclePositions` fields accept an object with a `url` and optional `headers` field to specify HTTP headers to include with the request, usually for authorization purposes.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"url\": \"https://www.bart.gov/dev/schedules/google_transit.zip\",\n      \"realtimeAlerts\": {\n        \"url\": \"https://api.bart.gov/gtfsrt/alerts.aspx\",\n        \"headers\": {\n          \"Authorization\": \"bearer 123456789\"\n        }\n      },\n      \"realtimeTripUpdates\": {\n        \"url\": \"https://api.bart.gov/gtfsrt/tripupdate.aspx\",\n        \"headers\": {\n          \"Authorization\": \"bearer 123456789\"\n        }\n      },\n      \"realtimeVehiclePositions\": {\n        \"url\": \"https://api.bart.gov/gtfsrt/vehiclepositions.aspx\",\n        \"headers\": {\n          \"Authorization\": \"bearer 123456789\"\n        }\n      }\n    }\n  ]\n}\n```\n\n- Specify multiple agencies to be imported into the same database\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/gtfs.zip\"\n    },\n    {\n      \"path\": \"/path/to/the/othergtfs.zip\"\n    }\n  ]\n}\n```\n\n- When importing multiple agencies their IDs may overlap. Specify a `prefix` to be added to every ID field to maintain uniqueness.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/gtfs.zip\",\n      \"prefix\": \"A\"\n    },\n    {\n      \"path\": \"/path/to/the/othergtfs.zip\",\n      \"prefix\": 10000\n    }\n  ]\n}\n```\n\n### csvOptions\n\n{Object} Add options to be passed to [`csv-parse`](https://csv.js.org/parse/) with the key `csvOptions`. This is an optional parameter.\n\nFor instance, if you wanted to skip importing invalid lines in the GTFS file:\n\n```json\n    \"csvOptions\": {\n      \"skip_lines_with_error\": true\n    }\n```\n\nSee [full list of options](https://csv.js.org/parse/options/).\n\n### db\n\n{Database Instance} When passing configuration to `importGtfs` in javascript, you can pass a `db` parameter with an existing database instance. This is not possible using a json configuration file Optional.\n\n```js\n// Using better-sqlite3 to open database\nimport { importGtfs } from 'gtfs';\nimport Database from 'better-sqlite3';\n\nconst db = new Database('/path/to/database');\n\nimportGtfs({\n  agencies: [\n    {\n      path: '/path/to/the/unzipped/gtfs/',\n    },\n  ],\n  db: db,\n});\n```\n\n```js\n// Using `openDb` from node-gtfs to open database\nimport { importGtfs, openDb } from 'gtfs';\n\nconst db = openDb({\n  sqlitePath: '/path/to/database',\n});\n\nimportGtfs({\n  agencies: [\n    {\n      path: '/path/to/the/unzipped/gtfs/',\n    },\n  ],\n  db: db,\n});\n```\n\n### downloadTimeout\n\n{Integer} A number of milliseconds to wait when downloading GTFS before throwing an error. Optional.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\"\n    }\n  ],\n  \"downloadTimeout\": 5000\n}\n```\n\n### exportPath\n\n{String} A path to a directory to put exported GTFS files. If the directory does not exist, it will be created. Used when running `gtfs-export` script or `exportGtfs()`. Optional, defaults to `gtfs-export/\u003cagency_name\u003e` where `\u003cagency_name\u003e` is a sanitized, [snake-cased](https://en.wikipedia.org/wiki/Snake_case) version of the first `agency_name` in `agency.txt`.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\"\n    }\n  ],\n  \"exportPath\": \"~/path/to/export/gtfs\"\n}\n```\n\n### gtfsRealtimeExpirationSeconds\n\n{Integer} Amount of time in seconds to allow GTFS-Realtime data to be stored in database before allowing to be deleted. Defaults to 0 (old GTFS-Realtime is deleted immediately when new data arrives). Note that if new data arrives for the same trip update, vehicle position or service alert before the expiration time, it will overwrite the existing data. The `gtfsRealtimeExpirationSeconds` only affects when data is deleted.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"url\": \"https://www.bart.gov/dev/schedules/google_transit.zip\",\n      \"realtimeAlerts\": {\n        \"url\": \"https://api.bart.gov/gtfsrt/alerts.aspx\"\n      },\n      \"realtimeTripUpdates\": {\n        \"url\": \"https://api.bart.gov/gtfsrt/tripupdate.aspx\"\n      },\n      \"realtimeVehiclePositions\": {\n        \"url\": \"https://api.bart.gov/gtfsrt/vehiclepositions.aspx\"\n      }\n    }\n  ],\n  \"gtfsRealtimeExpirationSeconds\": false\n}\n```\n\n### ignoreDuplicates\n\n{Boolean} If you don't want node-GTFS to throw an error when it encounters a duplicate id on GTFS import. If `true`, it will skip importing duplicate records where unique constraints are violated, such as`trip_id`, `stop_id`, `calendar_id`. Useful if importing GTFS from multiple sources into one SQlite database that share routes or stops. Defaults to `false`.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\"\n    }\n  ],\n  \"ignoreDuplicates\": false\n}\n```\n\n### ignoreErrors\n\n{Boolean} When importing GTFS from multiple agencies, if you don't want node-GTFS to throw an error and instead skip failed GTFS importants proceed to the next agency. Defaults to `false`.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\"\n    }\n  ],\n  \"ignoreErrors\": true\n}\n```\n\n### sqlitePath\n\n{String} A path to an SQLite database. Optional, defaults to using an in-memory database with a value of `:memory:`.\n\n```json\n    \"sqlitePath\": \"/dev/sqlite/gtfs\"\n```\n\n### verbose\n\n{Boolean} If you don't want the import script to print any output to the console, you can set `verbose` to `false`. Defaults to `true`.\n\n```json\n{\n  \"agencies\": [\n    {\n      \"path\": \"/path/to/the/unzipped/gtfs/\"\n    }\n  ],\n  \"verbose\": false\n}\n```\n\nIf you want to route logs to a custom function, you can pass a function that takes a single `text` argument as `logFunction`. This can't be defined in `config.json` but instead passed in a config object to `importGtfs()`. For example:\n\n```js\nimport { importGtfs } from 'gtfs';\n\nconst config = {\n  agencies: [\n    {\n      url: 'https://www.bart.gov/dev/schedules/google_transit.zip',\n      exclude: ['shapes'],\n    },\n  ],\n  logFunction: function (text) {\n    // Do something with the logs here, like save it or send it somewhere\n    console.log(text);\n  },\n};\n\nawait importGtfs(config);\n```\n\n## `gtfs-import` Script\n\nThe `gtfs-import` script reads from a JSON configuration file and imports the GTFS files specified to a SQLite database. [Read more on setting up your configuration file](#configuration).\n\n### Run the `gtfs-import` script from command-line\n\n    gtfs-import\n\nBy default, it will look for a `config.json` file in the project root. To specify a different path for the configuration file:\n\n    gtfs-import --configPath /path/to/your/custom-config.json\n\n### Use `importGtfs` script in code\n\nUse `importGtfs()` in your code to run an import of a GTFS file specified in a config.json file.\n\n```js\nimport { importGtfs } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\n\nawait importGtfs(config);\n```\n\nConfiguration can be a JSON object in your code\n\n```js\nimport { importGtfs } from 'gtfs';\n\nconst config = {\n  sqlitePath: '/dev/sqlite/gtfs',\n  agencies: [\n    {\n      url: 'https://www.bart.gov/dev/schedules/google_transit.zip',\n      exclude: ['shapes'],\n    },\n  ],\n};\n\nawait importGtfs(config);\n```\n\n## `gtfsrealtime-update` Script\n\nThe `gtfsrealtime-update` script requests GTFS-Realtime data and importings into a SQLite database. [GTFS-Realtime data](https://gtfs.org/realtime/reference/) can compliment GTFS Static data. [Read more about GTFS-Realtime configuration](#configuration).\n\n### Run the `gtfsrealtime-update` script from command-line\n\n    gtfsrealtime-update\n\nBy default, it will look for a `config.json` file in the project root. To specify a different path for the configuration file:\n\n    gtfsrealtime-update --configPath /path/to/your/custom-config.json\n\n### Use `updateGtfsRealtime` script in code\n\nUse `updateGtfsRealtime()` in your code to run an update of a GTFS-Realtime data specified in a config.json file.\n\n```js\nimport { updateGtfsRealtime } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\n\nawait updateGtfsRealtime(config);\n```\n\n## `gtfs-export` Script\n\nThe `gtfs-export` script reads from a JSON configuration file and exports data in GTFS format from a SQLite database. [Read more on setting up your configuration file](#configuration).\n\nThis could be used to export a GTFS file from SQLite after changes have been made to the data in the database manually.\n\n### Make sure to import GTFS data into SQLite first\n\nNothing will be exported if there is no data to export. See the [GTFS import script](#gtfs-import-script).\n\n### Run the `gtfs-export` script from Command-line\n\n    gtfs-export\n\nBy default, it will look for a `config.json` file in the project root. To specify a different path for the configuration file:\n\n    gtfs-export --configPath /path/to/your/custom-config.json\n\n### Command-Line options\n\n#### Specify path to config JSON file\n\nYou can specify the path to a config file to be used by the export script.\n\n    gtfs-export --configPath /path/to/your/custom-config.json\n\n#### Show help\n\nShow all command-line options\n\n    gtfs-export --help\n\n### Use `exportGtfs` script in code\n\nUse `exportGtfs()` in your code to run an export of a GTFS file specified in a config.json file.\n\n```js\nimport { exportGtfs } from 'gtfs';\n\nconst config = {\n  sqlitePath: '/dev/sqlite/gtfs',\n  agencies: [\n    {\n      url: 'https://www.bart.gov/dev/schedules/google_transit.zip',\n      exclude: ['shapes'],\n    },\n  ],\n};\n\nawait exportGtfs(config);\n```\n\n## Query Methods\n\nThis library includes many methods you can use in your project to query GTFS data. In addition to standard static GTFS, `node-gtfs` supports the following extensions to GTFS:\n\n- [GTFS-Realtime](https://gtfs.org/realtime/) - Realtime alerts, vehicle positions and predictions\n- [GTFS-Ride](https://gtfsride.org) - Passenger counts\n- [Operational Data Standard (ODS)](https://docs.calitp.org/operational-data-standard/) - Deadheads and personnel info\n- [GTFS-Timetables](https://gtfstohtml.com) - Information for creating human-readable timetables\n\nThere are also methods for retrieving stops and shapes in geoJSON format.\n\nMost query methods accept three optional arguments: `query`, `fields`, `sortBy` and `options`.\n\nFor more advanced queries, you can use `advancedQuery` or raw SQL queries using query method from [better-sqlite3](#raw-sqlite-query).\n\n### Database Setup\n\nTo use any of the query methods, first open the database using `openDb` before making any queries:\n\n```js\nimport { openDb } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\n\nconst db = openDb(config);\n```\n\nIf you no longer need a database (especially if using an in-memory database) you can use `closeDb`:\n\n```js\nimport { closeDb, openDb } from 'gtfs';\nconst db = openDb(config);\n\n// Do some stuff here\n\n// Close database connection when done.\ncloseDb(db);\n```\n\n### Deleting a Database\n\nYou can use `deleteDb` to delete a sqlite3 database from the filesystem.\n\n```js\nimport { deleteDb, openDb } from 'gtfs';\nconst db = openDb(config);\n\n// Do some stuff here\n\n// Delete the database\ndeleteDb(db);\n```\n\n### Examples\n\nFor example, to get a list of all routes with just `route_id`, `route_short_name` and `route_color` sorted by `route_short_name`:\n\n```js\nimport { closeDb, openDb, getRoutes } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\n\nconst db = openDb(config);\nconst routes = getRoutes(\n  {}, // No query filters\n  ['route_id', 'route_short_name', 'route_color'], // Only return these fields\n  [['route_short_name', 'ASC']], // Sort by this field and direction\n  { db: db }, // Options for the query. Can specify which database to use if more than one are open\n);\n\ncloseDb(db);\n```\n\nTo get a list of all trip_ids for a specific route:\n\n```js\nimport { closeDb, openDb, getTrips } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\n\nconst db = openDb(config);\nconst trips = getTrips(\n  {\n    route_id: '123',\n  },\n  ['trip_id'],\n);\n\ncloseDb(db);\n```\n\nTo get a few stops by specific stop_ids:\n\n```js\nimport { closeDb, openDb, getStops } from 'gtfs';\nimport { readFile } from 'fs/promises';\nimport path from 'node:path';\n\nconst config = JSON.parse(\n  await readFile(path.join(import.meta.dirname, 'config.json'))\n);\nconst db = openDb(config);\nconst stops = getStops(\n  {\n    stop_id: [\n      '123',\n      '234'\n      '345'\n    ]\n  }\n);\n\ncloseDb(db);\n```\n\n### Static GTFS Files\n\n#### getAgencies(query, fields, sortBy, options)\n\nReturns an array of agencies that match query parameters. [Details on agency.txt](https://gtfs.org/schedule/reference/#agencytxt)\n\n```js\nimport { getAgencies } from 'gtfs';\n\n// Get all agencies\nconst agencies = getAgencies();\n\n// Get a specific agency\nconst agencies = getAgencies({\n  agency_id: 'caltrain',\n});\n```\n\n#### getAreas(query, fields, sortBy, options)\n\nReturns an array of areas that match query parameters. [Details on areas.txt](https://gtfs.org/schedule/reference/#areastxt)\n\n```js\nimport { getAreas } from 'gtfs';\n\n// Get all areas\nconst areas = getAreas();\n\n// Get a specific area\nconst areas = getAreas({\n  area_id: 'area1',\n});\n```\n\n#### getAttributions(query, fields, sortBy, options)\n\nReturns an array of attributions that match query parameters. [Details on attributions.txt](https://gtfs.org/schedule/reference/#attributionstxt)\n\n```js\nimport { getAttributions } from 'gtfs';\n\n// Get all attributions\nconst attributions = getAttributions();\n\n// Get a specific attribution\nconst attributions = getAttributions({\n  attribution_id: '123',\n});\n```\n\n#### getBookingRules(query, fields, sortBy, options)\n\nReturns an array of booking rules that match query parameters. [Details on booking_rules.txt](https://gtfs.org/schedule/reference/#booking_rulestxt)\n\n```js\nimport { getBookingRules } from 'gtfs';\n\n// Get all booking rules\nconst bookingRules = getBookingRules();\n\n// Get a specific booking rule\nconst bookingRules = getBookingRules({\n  booking_rule_id: '1234',\n});\n```\n\n#### getRoutes(query, fields, sortBy, options)\n\nReturns an array of routes that match query parameters. [Details on routes.txt](https://gtfs.org/schedule/reference/#routestxt)\n\n```js\nimport { getRoutes } from 'gtfs';\n\n// Get all routes, sorted by route_short_name\nconst routes = getRoutes({}, [], [['route_short_name', 'ASC']]);\n\n// Get a specific route\nconst routes = getRoutes({\n  route_id: 'Lo-16APR',\n});\n\n/*\n * `getRoutes` allows passing a `stop_id` as part of the query. This will\n * query stoptimes and trips to find all routes that serve that `stop_id`.\n */\nconst routes = getRoutes(\n  {\n    stop_id: '70011',\n  },\n  [],\n  [['stop_name', 'ASC']],\n);\n```\n\n#### getStops(query, fields, sortBy, options)\n\nReturns an array of stops that match query parameters. [Details on stops.txt](https://gtfs.org/schedule/reference/#stopstxt)\n\n```js\nimport { getStops } from 'gtfs';\n\n// Get all stops\nconst stops = getStops();\n\n// Get a specific stop by stop_id\nconst stops = getStops({\n  stop_id: '70011',\n});\n\n/*\n * `getStops` allows passing a `route_id` in the query and it will\n * query trips and stoptimes to find all stops served by that `route_id`.\n */\nconst stops = getStops({\n  route_id: 'Lo-16APR',\n});\n\n/*\n * `getStops` allows passing a `trip_id` in the query and it will query\n * stoptimes to find all stops on that `trip_id`.\n */\nconst stops = getStops({\n  trip_id: '37a',\n});\n\n/*\n * `getStops` allows passing a `shape_id` in the query and it will query\n * trips and stoptimes to find all stops that use that `shape_id`.\n */\nconst stops = getStops({\n  shape_id: 'cal_sf_tam',\n});\n\n/*\n * `getStops` allows passing a `bounding_box_side_m` value in the options\n * parameter object. If included, it will return all stops within a square\n * bounding box around the `stop_lat` and `stop_lon` parameters passed to\n * the query using the size in meters specified.\n */\nconst stops = getStops(\n  {\n    stop_lat: 37.58764,\n    stop_lon: -122.36265,\n  },\n  [],\n  [],\n  {\n    bounding_box_side_m: 1000\n  }\n);\n```\n\n#### getStopsAsGeoJSON(query, options)\n\nReturns geoJSON object of stops that match query parameters. Stops will include all properties of each stop from stops.txt and stop_attributes.txt if present. All valid queries for `getStops()` work for `getStopsAsGeoJSON()`.\n\n```js\nimport { getStopsAsGeoJSON } from 'gtfs';\n\n// Get all stops for an agency as geoJSON\nconst stopsGeojson = getStopsAsGeoJSON();\n\n// Get all stops for a specific route as geoJSON\nconst stopsGeojson = getStopsAsGeoJSON({\n  route_id: 'Lo-16APR',\n});\n\n// Get all stops within a 1000m bounding box as geoJSON\nconst stopsGeojson = getStopsAsGeoJSON(\n  {\n    stop_lat: 37.58764,\n    stop_lon: -122.36265,\n  },\n  {\n    bounding_box_side_m: 1000,\n  },\n);\n```\n\n#### getStoptimes(query, fields, sortBy, options)\n\nReturns an array of stop_times that match query parameters. [Details on stop_times.txt](https://gtfs.org/schedule/reference/#stop_timestxt)\n\n```js\nimport { getStoptimes } from 'gtfs';\n\n// Get all stoptimes\nconst stoptimes = getStoptimes();\n\n// Get all stoptimes for a specific stop\nconst stoptimes = getStoptimes({\n  stop_id: '70011',\n});\n\n// Get all stoptimes for a specific trip, sorted by stop_sequence\nconst stoptimes = getStoptimes(\n  {\n    trip_id: '37a',\n  },\n  [],\n  [['stop_sequence', 'ASC']],\n);\n\n// Get all stoptimes for a specific stop and service_id\nconst stoptimes = getStoptimes({\n  stop_id: '70011',\n  service_id: 'CT-16APR-Caltrain-Weekday-01',\n});\n\n/*\n * `getStoptimes` allows passing a `date` in the query to return\n * only stoptimes for a specific day.\n */\nconst stoptimes = getStoptimes({\n  stop_id: '70011',\n  date: 20160704\n});\n\n/*\n * `getStoptimes` allows passing a `start_time` and/or and \n * `end_time` in the query to return only stoptimes after \n * start_time and before end_time. This can be combined with the \n * `date` parameter to get upcoming stoptimes\n */\nconst stoptimes = getStoptimes({\n  stop_id: '70011',\n  date: 20160704,\n  start_time: '11:30:00',\n  end_time: '11:45:00'\n});\n```\n\n#### getTrips(query, fields, sortBy, options)\n\nReturns an array of trips that match query parameters. [Details on trips.txt](https://gtfs.org/schedule/reference/#tripstxt)\n\n```js\nimport { getTrips } from 'gtfs';\n\n// Get all trips\nconst trips = getTrips();\n\n// Get trips for a specific route and direction\nconst trips = getTrips({\n  route_id: 'Lo-16APR',\n  direction_id: 0\n});\n\n// Get trips for direction '' or null\nconst trips = getTrips({\n  route_id: 'Lo-16APR',\n  direction_id: null\n});\n\n// Get trips for a specific route and direction limited by a service_id\nconst trips = getTrips({\n  route_id: 'Lo-16APR',\n  direction_id: 0,\n  service_id: '\n});\n```\n\n#### getShapes(query, fields, sortBy, options)\n\nReturns an array of shapes that match query parameters. [Details on shapes.txt](https://gtfs.org/schedule/reference/#shapestxt)\n\n```js\nimport { getShapes } from 'gtfs';\n\n// Get all shapes for an agency\nconst shapes = getShapes();\n\n/*\n * `getShapes` allows passing a `route_id` in the query and it will query\n * trips to find all shapes served by that `route_id`.\n */\nconst shapes = getShapes({\n  route_id: 'Lo-16APR',\n});\n\n/*\n * `getShapes` allows passing a `trip_id` in the query and it will query\n * trips to find all shapes served by that `trip_id`.\n */\nconst shapes = getShapes({\n  trip_id: '37a',\n});\n\n/*\n * `getShapes` allows passing a `service_id` in the query and it will query\n * trips to find all shapes served by that `service_id`.\n */\nconst shapes = getShapes({\n  service_id: 'CT-16APR-Caltrain-Sunday-02',\n});\n```\n\n#### getShapesAsGeoJSON(query, options)\n\nReturns a geoJSON object of shapes that match query parameters. Shapes will include all properties of each route from routes.txt and route_attributes.txt if present. All valid queries for `getShapes()` work for `getShapesAsGeoJSON()`.\n\n```js\nimport { getShapesAsGeoJSON } from 'gtfs';\n\n// Get geoJSON of all routes in an agency\nconst shapesGeojson = getShapesAsGeoJSON();\n\n// Get geoJSON of shapes for a specific route\nconst shapesGeojson = getShapesAsGeoJSON({\n  route_id: 'Lo-16APR',\n});\n\n// Get geoJSON of shapes for a specific trip\nconst shapesGeojson = getShapesAsGeoJSON({\n  trip_id: '37a',\n});\n\n// Get geoJSON of shapes for a specific `service_id`\nconst shapesGeojson = getShapesAsGeoJSON({\n  service_id: 'CT-16APR-Caltrain-Sunday-02',\n});\n\n// Get geoJSON of shapes for a specific `shape_id`\nconst shapesGeojson = getShapesAsGeoJSON({\n  shape_id: 'cal_sf_tam',\n});\n```\n\n#### getCalendars(query, fields, sortBy, options)\n\nReturns an array of calendars that match query parameters. [Details on calendar.txt](https://gtfs.org/schedule/reference/#calendartxt)\n\n```js\nimport { getCalendars } from 'gtfs';\n\n// Get all calendars for an agency\nconst calendars = getCalendars();\n\n// Get calendars for a specific `service_id`\nconst calendars = getCalendars({\n  service_id: 'CT-16APR-Caltrain-Sunday-02',\n});\n```\n\n#### getServiceIdsByDate(date, options)\n\nReturns an array of service_ids for a specified date. It queries both calendars.txt and calendar_dates.txt to calculate which service_ids are effective for that date, including exceptions. The `date` field is an integer in yyyymmdd format.\n\n```js\nimport { getServiceIdsByDate } from 'gtfs';\n\n// Get service_ids for a specifc date\nconst serviceIds = getServiceIdsByDate(20240704);\n```\n\n#### getCalendarDates(query, fields, sortBy, options)\n\nReturns an array of calendar_dates that match query parameters. [Details on calendar_dates.txt](https://gtfs.org/schedule/reference/#calendar_datestxt)\n\n```js\nimport { getCalendarDates } from 'gtfs';\n\n// Get all calendar_dates for an agency\nconst calendarDates = getCalendarDates();\n\n// Get calendar_dates for a specific `service_id`\nconst calendarDates = getCalendarDates({\n  service_id: 'CT-16APR-Caltrain-Sunday-02',\n});\n```\n\n#### getFareAttributes(query, fields, sortBy, options)\n\nReturns an array of fare_attributes that match query parameters. [Details on fare_attributes.txt](https://gtfs.org/schedule/reference/#fare_attributestxt)\n\n```js\nimport { getFareAttributes } from 'gtfs';\n\n// Get all `fare_attributes` for an agency\nconst fareAttributes = getFareAttributes();\n\n// Get `fare_attributes` for a specific `fare_id`\nconst fareAttributes = getFareAttributes({\n  fare_id: '123',\n});\n```\n\n#### getFareLegRules(query, fields, sortBy, options)\n\nReturns an array of fare_leg_rules that match query parameters. [Details on fare_leg_rules.txt](https://gtfs.org/schedule/reference/#fare_leg_rulestxt)\n\n```js\nimport { getFareLegRules } from 'gtfs';\n\n// Get all fare leg rules\nconst fareLegRules = getFareLegRules();\n\n// Get fare leg rules for a specific fare product\nconst fareLegRules = getFareLegRules({\n  fare_product_id: 'product1',\n});\n```\n\n#### getFareMedia(query, fields, sortBy, options)\n\nReturns an array of fare_media that match query parameters. [Details on fare_media.txt](https://gtfs.org/schedule/reference/#fare_mediatxt)\n\n```js\nimport { getFareMedia } from 'gtfs';\n\n// Get all fare media\nconst getFareMedia = getFareMedia();\n\n// Get a specific fare media\nconst fareMedia = getFareMedia({\n  fare_media_id: 'media1',\n});\n```\n\n#### getFareProducts(query, fields, sortBy, options)\n\nReturns an array of fare_products that match query parameters. [Details on fare_products.txt](https://gtfs.org/schedule/reference/#fare_productstxt)\n\n```js\nimport { getFareProducts } from 'gtfs';\n\n// Get all fare products\nconst fareProducts = getFareProducts();\n\n// Get a specific fare product\nconst fareProducts = getFareProducts({\n  fare_product_id: 'product1',\n});\n```\n\n#### getFareRules(query, fields, sortBy, options)\n\nReturns an array of fare_rules that match query parameters. [Details on fare_rules.txt](https://gtfs.org/schedule/reference/#fare_rulestxt)\n\n```js\nimport { getFareRules } from 'gtfs';\n\n// Get all `fare_rules` for an agency\nconst fareRules = getFareRules();\n\n// Get fare_rules for a specific route\nconst fareRules = getFareRules({\n  route_id: 'Lo-16APR',\n});\n```\n\n#### getFareTransferRules(query, fields, sortBy, options)\n\nReturns an array of fare_transfer_rules that match query parameters. [Details on fare_transfer_rules.txt](https://gtfs.org/schedule/reference/#fare_transfer_rulestxt)\n\n```js\nimport { getFareTransferRules } from 'gtfs';\n\n// Get all fare transfer rules\nconst fareTransferRules = getFareTransferRules();\n\n// Get a all fare transfer rules for a specific fare product\nconst fareTransferRules = getFareTransferRules({\n  fare_product_id: 'product1',\n});\n```\n\n#### getFeedInfo(query, fields, sortBy, options)\n\nReturns an array of feed_info that match query parameters. [Details on feed_info.txt](https://gtfs.org/schedule/reference/#feed_infotxt)\n\n```js\nimport { getFeedInfo } from 'gtfs';\n\n// Get feed_info\nconst feedInfo = getFeedInfo();\n```\n\n#### getFrequencies(query, fields, sortBy, options)\n\nReturns an array of frequencies that match query parameters. [Details on frequencies.txt](https://gtfs.org/schedule/reference/#frequenciestxt)\n\n```js\nimport { getFrequencies } from 'gtfs';\n\n// Get all frequencies\nconst frequencies = getFrequencies();\n\n// Get frequencies for a specific trip\nconst frequencies = getFrequencies({\n  trip_id: '1234',\n});\n```\n\n#### getLevels(query, fields, sortBy, options)\n\nReturns an array of levels that match query parameters. [Details on levels.txt](https://gtfs.org/schedule/reference/#levelstxt)\n\n```js\nimport { getLevels } from 'gtfs';\n\n// Get all levels\nconst levels = getLevels();\n```\n\n#### getLocationGroups(query, fields, sortBy, options)\n\nReturns an array of location groups that match query parameters. [Details on location_groups.txt](https://gtfs.org/schedule/reference/#location_groupstxt)\n\n```js\nimport { getLocationGroups } from 'gtfs';\n\n// Get all location groups\nconst locationGroups = getLocationGroups();\n\n// Get a specific location group\nconst locationGroups = getLocationGroups({\n  location_group_id: '1234',\n});\n```\n\n#### getLocationGroupStops(query, fields, sortBy, options)\n\nReturns an array of location group stops that match query parameters. [Details on location_group_stops.txt](https://gtfs.org/schedule/reference/#location_group_stopstxt)\n\n```js\nimport { getLocationGroupStops } from 'gtfs';\n\n// Get all location group stops\nconst locationGroupStops = getLocationGroupStops();\n\n// Get location group stops for a specific stop_id\nconst locationGroups = getLocationGroupStops({\n  stop_id: '1234',\n});\n```\n\n#### getLocations(query, fields, sortBy, options)\n\nReturns an array of locations that match query parameters. Each location is text that can be parsed into a geojson object. [Details on locations.geojson](https://gtfs.org/schedule/reference/#locationsgeojson)\n\n```js\nimport { getLocations } from 'gtfs';\n\n// Get all locations\nconst locations = getLocations();\n```\n\n#### getPathways(query, fields, sortBy, options)\n\nReturns an array of pathways that match query parameters. [Details on pathways.txt](https://gtfs.org/schedule/reference/#pathwaystxt)\n\n```js\nimport { getPathways } from 'gtfs';\n\n// Get all pathways\nconst pathways = getPathways();\n```\n\n#### getTimeframes(query, fields, sortBy, options)\n\nReturns an array of timeframes that match query parameters. [Details on timeframes.txt](https://gtfs.org/schedule/reference/#timeframestxt)\n\n```js\nimport { getTimeframes } from 'gtfs';\n\n// Get all timeframes\nconst timeframes = getTimeframes();\n```\n\n#### getTransfers(query, fields, sortBy, options)\n\nReturns an array of transfers that match query parameters. [Details on transfers.txt](https://gtfs.org/schedule/reference/#transferstxt)\n\n```js\nimport { getTransfers } from 'gtfs';\n\n// Get all transfers\nconst transfers = getTransfers();\n\n// Get transfers for a specific stop\nconst transfers = getTransfers({\n  from_stop_id: '1234',\n});\n```\n\n#### getTranslations(query, fields, sortBy, options)\n\nReturns an array of translations that match query parameters. [Details on translations.txt](https://gtfs.org/schedule/reference/#translationstxt)\n\n```js\nimport { getTranslations } from 'gtfs';\n\n// Get all translations\nconst translations = getTranslations();\n```\n\n#### getStopAreas(query, fields, sortBy, options)\n\nReturns an array of stop_areas that match query parameters. [Details on stop_areas.txt](https://gtfs.org/schedule/reference/#stop_areastxt)\n\n```js\nimport { getStopAreas } from 'gtfs';\n\n// Get all stop areas\nconst stopAreas = getStopAreas();\n```\n\n#### getNetworks(query, fields, sortBy, options)\n\nReturns an array of networks that match query parameters. [Details on networks.txt](https://gtfs.org/schedule/reference/#networkstxt)\n\n```js\nimport { getNetworks } from 'gtfs';\n\n// Get all networks\nconst networks = getNetworks();\n\n// Get networks for a specific network_id\nconst networks = getNetworks({\n  network_id: '1234',\n});\n```\n\n#### getRouteNetworks(query, fields, sortBy, options)\n\nReturns an array of route_networks that match query parameters. [Details on route_networks.txt](https://gtfs.org/schedule/reference/#route_networkstxt)\n\n```js\nimport { getRouteNetworks } from 'gtfs';\n\n// Get all route_networks\nconst routeNetworks = getRouteNetworks();\n\n// Get route_networks for a specific network_id\nconst routeNetworks = getRouteNetworks({\n  network_id: '1234',\n});\n```\n\n### GTFS-Timetables files\n\n#### getTimetables(query, fields, sortBy, options)\n\nReturns an array of timetables that match query parameters. This is for the non-standard `timetables.txt` file used in GTFS-to-HTML. [Details on timetables.txt](https://gtfstohtml.com/docs/timetables)\n\n```js\nimport { getTimetables } from 'gtfs';\n\n// Get all timetables for an agency\nconst timetables = getTimetables();\n\n// Get a specific timetable\nconst timetables = getTimetables({\n  timetable_id: '1',\n});\n```\n\n#### getTimetableStopOrders(query, fields, sortBy, options)\n\nReturns an array of timetable_stop_orders that match query parameters. This is for the non-standard `timetable_stop_order.txt` file used in GTFS-to-HTML. [Details on timetable_stop_order.txt](https://gtfstohtml.com/docs/timetable-stop-order)\n\n```js\nimport { getTimetableStopOrders } from 'gtfs';\n\n// Get all timetable_stop_orders\nconst timetableStopOrders = getTimetableStopOrders();\n\n// Get timetable_stop_orders for a specific timetable\nconst timetableStopOrders = getTimetableStopOrders({\n  timetable_id: '1',\n});\n```\n\n#### getTimetablePages(query, fields, sortBy, options)\n\nReturns an array of timetable_pages that match query parameters. This is for the non-standard `timetable_pages.txt` file used in GTFS-to-HTML. [Details on timetable_pages.txt](https://gtfstohtml.com/docs/timetable-pages)\n\n```js\nimport { getTimetablePages } from 'gtfs';\n\n// Get all timetable_pages for an agency\nconst timetablePages = getTimetablePages();\n\n// Get a specific timetable_page\nconst timetablePages = getTimetablePages({\n  timetable_page_id: '2',\n});\n```\n\n#### getTimetableNotes(query, fields, sortBy, options)\n\nReturns an array of timetable_notes that match query parameters. This is for the non-standard `timetable_notes.txt` file used in GTFS-to-HTML. [Details on timetable_notes.txt](https://gtfstohtml.com/docs/timetable-notes)\n\n```js\nimport { getTimetableNotes } from 'gtfs';\n\n// Get all timetable_notes for an agency\nconst timetableNotes = getTimetableNotes();\n\n// Get a specific timetable_note\nconst timetableNotes = getTimetableNotes({\n  note_id: '1',\n});\n```\n\n#### getTimetableNotesReferences(query, fields, sortBy, options)\n\nReturns an array of timetable_notes_references that match query parameters. This is for the non-standard `timetable_notes_references.txt` file used in GTFS-to-HTML. [Details on timetable_notes_references.txt](https://gtfstohtml.com/docs/timetable-notes-references)\n\n```js\nimport { getTimetableNotesReferences } from 'gtfs';\n\n// Get all timetable_notes_references for an agency\nconst timetableNotesReferences = getTimetableNotesReferences();\n\n// Get all timetable_notes_references for a specific timetable\nconst timetableNotesReferences = getTimetableNotesReferences({\n  timetable_id: '4',\n});\n```\n\n### GTFS-Realtime\n\nIn order to use GTFS-Realtime query methods, you must first run the [GTFS-Realtime update script or function](#gtfsrealtime-update-script) to pull data into your database.\n\n#### getServiceAlerts(query, fields, sortBy, options)\n\nReturns an array of GTFS Realtime service alerts that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest service alerts from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).\n\n[More details on Service Alerts](https://gtfs.org/realtime/feed-entities/service-alerts/)\n\n```js\nimport { getServiceAlerts } from 'gtfs';\n\n// Get service alerts\nconst serviceAlerts = getServiceAlerts();\n```\n\n#### getTripUpdates(query, fields, sortBy, options)\n\nReturns an array of GTFS Realtime trip updates that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest trip updates from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).\n\n[More details on Trip Updates](https://gtfs.org/realtime/feed-entities/trip-updates/)\n\n```js\nimport { getTripUpdates } from 'gtfs';\n\n// Get all trip updates\nconst tripUpdates = getTripUpdates();\n```\n\n#### getStopTimeUpdates(query, fields, sortBy, options)\n\nReturns an array of GTFS Realtime stop time updates that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest stop time updates from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).\n\n[More details on Stop Time Updates](https://gtfs.org/realtime/feed-entities/trip-updates/#stoptimeupdate)\n\n```js\nimport { getStopTimeUpdates } from 'gtfs';\n\n// Get all stop time updates\nconst stopTimeUpdates = getStopTimeUpdates();\n```\n\n#### getVehiclePositions(query, fields, sortBy, options)\n\nReturns an array of GTFS Realtime vehicle positions that match query parameters. Note that this does not refresh the data from GTFS-Realtime feeds, it only fetches what is stored in the database. In order to fetch the latest vehicle positions from GTFS-Realtime feeds and store in your database, use the [GTFS-Realtime update script or function](#gtfsrealtime-update-script).\n\n[More details on Vehicle Positions](https://gtfs.org/realtime/feed-entities/vehicle-positions/)\n\n```js\nimport { getVehiclePositions } from 'gtfs';\n\n// Get all vehicle position data\nconst vehiclePositions = getVehiclePositions();\n```\n\n### GTFS+ Files\n\n#### getCalendarAttributes(query, fields, sortBy, options)\n\nReturns an array of calendar_attributes that match query parameters.\n\n```js\nimport { getCalendarAttributes } from 'gtfs';\n\n// Get all calendar attributes\nconst calendarAttributes = getCalendarAttributes();\n\n// Get calendar attributes for specific service\nconst calendarAttributes = getCalendarAttributes({\n  service_id: '1234',\n});\n```\n\n#### getDirections(query, fields, sortBy, options)\n\nReturns an array of directions that match query parameters.\n\n```js\nimport { getDirections } from 'gtfs';\n\n// Get all directions\nconst directions = getDirections();\n\n// Get directions for a specific route\nconst directions = getDirections({\n  route_id: '1234',\n});\n\n// Get directions for a specific route and direction\nconst directions = getDirections({\n  route_id: '1234',\n  direction_id: 1,\n});\n```\n\n#### getRouteAttributes(query, fields, sortBy, options)\n\nReturns an array of route_attributes that match query parameters.\n\n```js\nimport { getRouteAttributes } from 'gtfs';\n\n// Get all route attributes\nconst routeAttributes = getRouteAttributes();\n\n// Get route attributes for specific route\nconst routeAttributes = getRouteAttributes({\n  route_id: '1234',\n});\n```\n\n#### getStopAttributes(query, fields, sortBy, options)\n\nReturns an array of stop_attributes that match query parameters.\n\n```js\nimport { getStopAttributes } from 'gtfs';\n\n// Get all stop attributes\nconst stopAttributes = getStopAttributes();\n\n// Get stop attributes for specific stop\nconst stopAttributes = getStopAttributes({\n  stop_id: '1234',\n});\n```\n\n### GTFS-Ride Files\n\nSee full [documentation of GTFS Ride](https://gtfsride.org).\n\n#### getBoardAlights(query, fields, sortBy, options)\n\nReturns an array of board_alight that match query parameters. [Details on board_alight.txt](http://gtfsride.org/specification#board_alighttxt)\n\n```js\nimport { getBoardAlights } from 'gtfs';\n\n// Get all board_alight\nconst boardAlights = getBoardAlights();\n\n// Get board_alight for a specific trip\nconst boardAlights = getBoardAlights({\n  trip_id: '123',\n});\n```\n\n#### getRideFeedInfo(query, fields, sortBy, options)\n\nReturns an array of ride_feed_info that match query parameters. [Details on ride_feed_info.txt](http://gtfsride.org/specification#ride_feed_infotxt)\n\n```js\nimport { getRideFeedInfo } from 'gtfs';\n\n// Get all ride_feed_info\nconst rideFeedInfos = getRideFeedInfo();\n```\n\n#### getRiderTrips(query, fields, sortBy, options)\n\nReturns an array of rider_trip that match query parameters. [Details on rider_trip.txt](http://gtfsride.org/specification#rider_triptxt)\n\n```js\nimport { getRiderTrips } from 'gtfs';\n\n// Get all rider_trip\nconst riderTrips = getRiderTrips();\n\n// Get rider_trip for a specific trip\nconst riderTrips = getRiderTrips({\n  trip_id: '123',\n});\n```\n\n#### getRidership(query, fields, sortBy, options)\n\nReturns an array of ridership that match query parameters. [Details on ridership.txt](http://gtfsride.org/specification#ridershiptxt)\n\n```js\nimport { getRidership } from 'gtfs';\n\n// Get all ridership\nconst riderships = getRidership();\n\n// Get ridership for a specific route\nconst riderships = getRidership({\n  route_id: '123',\n});\n```\n\n#### getTripCapacities(query, fields, sortBy, options)\n\nReturns an array of trip_capacity that match query parameters. [Details on trip_capacity.txt](http://gtfsride.org/specification#trip_capacitytxt)\n\n```js\nimport { getTripCapacities } from 'gtfs';\n\n// Get all trip_capacity\nconst tripCapacities = getTripCapacities();\n\n// Get trip_capacity for a specific trip\nconst tripCapacities = getTripCapacities({\n  trip_id: '123',\n});\n```\n\n### Operational Data Standard (ODS) Files\n\n#### getDeadheads(query, fields, sortBy, options)\n\nReturns an array of deadheads that match query parameters. [Details on deadheads.txt](https://docs.calitp.org/operational-data-standard/spec/#deadheadstxt)\n\n```js\nimport { getDeadheads } from 'gtfs';\n\n// Get all deadheads\nconst deadheads = getDeadheads();\n\n// Get deadheads for a specific block\nconst deadheads = getDeadheads({\n  block_id: '123',\n});\n```\n\n#### getDeadheadTimes(query, fields, sortBy, options)\n\nReturns an array of deadhead_times that match query parameters. [Details on deadhead_times.txt](https://docs.calitp.org/operational-data-standard/spec/#deadhead_timestxt)\n\n```js\nimport { getDeadheadTimes } from 'gtfs';\n\n// Get all deadhead_times\nconst deadheadTimes = getDeadheadTimes();\n\n// Get deadhead_times for a specific deadhead\nconst deadheadTimes = getDeadheadTimes({\n  deadhead_id: '123',\n});\n```\n\n#### getOpsLocations(query, fields, sortBy, options)\n\nReturns an array of ops_locations that match query parameters. [Details on ops_locations.txt](https://docs.calitp.org/operational-data-standard/spec/#ops_locationstxt)\n\n```js\nimport { getOpsLocations } from 'gtfs';\n\n// Get all ops_locations\nconst opsLocations = getOpsLocations();\n\n// Get a specific ops_locations\nconst opsLocations = getOpsLocations({\n  ops_location_id: '123',\n});\n```\n\n#### getRunsPieces(query, fields, sortBy, options)\n\nReturns an array of runs_pieces that match query parameters. [Details on runs_pieces.txt](https://docs.calitp.org/operational-data-standard/spec/#runs_piecestxt)\n\n```js\nimport { getRunsPieces } from 'gtfs';\n\n// Get all runs_pieces\nconst runsPieces = getRunsPieces();\n```\n\n#### getRunEvents(query, fields, sortBy, options)\n\nReturns an array of run_events that match query parameters. [Details on run_events.txt](https://docs.calitp.org/operational-data-standard/spec/#run_eventstxt)\n\n```js\nimport { getRunEvents } from 'gtfs';\n\n// Get all run_events\nconst runEvents = runEvents();\n\n// Get a run_events for a specific piece\nconst runEvents = runEvents({\n  piece_id: '123',\n});\n```\n\n### Other Non-standard GTFS Files\n\n#### getTripsDatedVehicleJourneys(query, fields, sortBy, options)\n\nReturns an array of trips_dated_vehicle_journey that match query parameters. This is for the non-standard `trips_dated_vehicle_journey.txt` file. [Details on trips_dated_vehicle_journey.txt](https://www.trafiklab.se/api/trafiklab-apis/gtfs-regional/extra-files/)\n\n```js\nimport { getTripsDatedVehicleJourneys } from 'gtfs';\n\n// Get all trips_dated_vehicle_journey\nconst tripsDatedVehicleJourneys = getTripsDatedVehicleJourneys();\n```\n\n### Advanced Query Methods\n\n#### advancedQuery(table, advancedQueryOptions)\n\nQueries the database with support for table joins and custom tables and returns an array of data.\n\n```js\nimport { advancedQuery } from 'gtfs';\n\n// Example `advancedQuery` joining stop_times with trips.\nconst advancedQueryOptions = {\n  query: {\n    'stop_times.trip_id': tripId,\n  },\n  fields: ['stop_times.trip_id', 'arrival_time'],\n  join: [\n    {\n      type: 'INNER',\n      table: 'trips',\n      on: 'stop_times.trip_id=trips.trip_id',\n    },\n  ],\n};\n\nconst stoptimes = advancedQuery('stop_times', advancedQueryOptions);\n```\n\n#### Raw SQLite Query\n\nUse the `openDb` function to get the db object, and then use any query method from [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) to query GTFS data.\n\n```js\nimport { openDb } from 'gtfs';\nconst db = openDb(config);\n\n// Get a specific trip\nconst trip = db.prepare('SELECT * FROM trips WHERE trip_id = ?').get('123');\n\n// Get all stops\nconst stops = db.prepare('SELECT * from stops').all();\n\n// Get all calendar_ids for specific date\nconst calendarIds = db\n  .prepare(\n    'SELECT service_id from calendar WHERE start_date \u003c= $date AND end_date \u003e= $date'\n  )\n  .all({ date: 20150101 });\n\n// Find all stops for route_id=18 by joining tables\nconst stopIds = db\n  .prepare(\n    'SELECT DISTINCT stops.stop_id from stops INNER JOIN stop_times ON stops.stop_id = stop_times.stop_id INNER JOIN trips on trips.trip_id = stop_times.trip_id WHERE trips.route_id = ?'\n  )\n  .all('18');\n\n// Execute raw SQL\nconst sql = \"DELETE FROM trips where trip_id = '329'\";\ndb.exec(sql);\n```\n\n## Contributing\n\nPull requests are welcome, as is feedback and [reporting issues](https://github.com/blinktaginc/node-gtfs/issues).\n\n### Tests\n\nTo run tests:\n\n    npm test\n\nTo run a specific test:\n\n    npm test -- get-stoptimes\n","funding_links":[],"categories":["Producing Data","sqlite","Consumption","Uncategorized"],"sub_categories":["GTFS","Mobility and Transportation","Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlinkTagInc%2Fnode-gtfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBlinkTagInc%2Fnode-gtfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBlinkTagInc%2Fnode-gtfs/lists"}