Quick Start
Command Line Usage#
The gtfs-to-html command-line utility will download the GTFS file specified in config.js and then build the HTML timetables and save them in html/:agency_key.
If you would like to use this library as a command-line utility, you can install it globally directly from npm:
npm install gtfs-to-html -gThen you can run gtfs-to-html.
gtfs-to-htmlCommand-line options#
configPath
Allows specifying a path to a configuration json file. By default, gtfs-to-html will look for a config.json file in the directory it is being run from.
gtfs-to-html --configPath /path/to/your/custom-config.jsonskipImport
Skips importing GTFS into SQLite. Useful if you are rerunning with an unchanged GTFS file. If you use this option and the GTFS file hasn't been imported, you'll get an error.
gtfs-to-html --skipImportProcessing very large GTFS files.#
By default, node has a memory limit of 512 MB or 1 GB. If you have a very large GTFS file and want to use the option showOnlyTimepoint = false you may need to allocate more memory. Use the max-old-space-size option. For example to allocate 4 GB:
NODE_OPTIONS=--max_old_space_size=4096 gtfs-to-htmlDocker Usage#
A Dockerfile is available in the docker directory. You can use docker to run GTFS-to-HTML.
Create a config.json file and save in the same directory as your
Dockerfile. You can useconfig-sample.jsonfrom the project root as a starting point.Build the docker image:
docker build -t gtfs-to-html .Run the docker image:
docker run gtfs-to-htmlCopy the generated HTML out of the docker container
// Figure out what your container ID is docker container ls -a // Then copy the html folder from that container docker cp <YOUR IMAGE CONTAINER ID>:/html . // For example: docker cp ca45a38963d9:/html .
Usage as a node module#
If you are using this as a node module as part of an application, you can include it in your project's package.json file.
Code example#
import gtfsToHtml from 'gtfs-to-html'; import { readFile } from 'fs/promises'; const config = JSON.parse(await readFile(new URL('./config.json', import.meta.url)));
gtfsToHtml(config) .then(() => { console.log('HTML Generation Successful'); process.exit(); }) .catch(err => { console.error(err); process.exit(1); });Example Application#
An example Express application that uses gtfs-to-html is included in the app folder. After an initial run of gtfs-to-html, the GTFS data will be downloaded and loaded into SQLite.
You can view an individual route HTML on demand by running the included Express app:
node appBy default, gtfs-to-html will look for a config.json file in the project root. To specify a different path for the configuration file:
node app --configPath /path/to/your/custom-config.jsonOnce running, you can view the HTML in your browser at localhost:3000
Usage as a hosted web app#
A hosted version of GTFS-to-HTML as a service allows you to use it entirely within your browser - no downloads or command line necessary.
It provides:
- a web-based interface for finding GTFS feeds or ability to enter your own URL
- support for adding custom configuration as JSON
- creation of HTML timetables as a downloadable .zip file
- a preview of all timetables generated directly in your browser
Currently, it is limited to relatively small GTFS files and doesn't offer support for Custom Templates.
Troubleshooting#
SQLite3 unable to be installed with Failed to exec install script#
For an error like:
lifecycle sqlite3@5.0.0~install: Failed to exec install script
Try installing gtfs-to-html using the following flags:
npm install --unsafe-perm --allow-root -g