This is the API for my Citi Bike Map project. You can view of live version here.
It's a simple express backend with only one POST
endpoint at /trips
. It accepts one request parameter, dateAndTime
, in the form 2017-09-01T07:00:00-04:00
. The return object contains all trips for that date and time and an object containing coordinates that represent the route of the trip.
The trip data lives in MongoDB instance and was downloaded from Citi Bike.
The routes are derived from the trip data using the start station of the trip and the end station with OSRM as the engine.
After cloning the repo:
Run npm install
.
Download the trip data. You can use the script I created by running node scripts/download.js
to download the data for September 2017.
Setup a local instance of MongoDB and import the CSV into the DB by running the following command in your Mongo bin directory:
./mongoimport --host=127.0.0.1 -d [DatabaseName] -c [CollectionName] --type csv --file [PathToCSV] --headerline
You'll need to update the Date field in every document in the collection and convert it from a string into an actual date object. You can check out the scripts/updatedb.js
for an example of how to do so.
You'll also need to setup the OSRM engine. The reason this repo is so large is because I've included the raw OpenStreetMap dataset for New York City that I found here. This process takes a while but run npm run heroku-postbuild
to setup the routing engine. You can find out more about OSRM and node here.
Once everything is setup, run npm run serve
to start a local server up.
If you'd like to create a production build, run npm run build
.