net-art-uchicago / cta-file-sharing

a collaborative artware project by Media Art and Design students at the University of Chicago.
GNU General Public License v3.0
2 stars 15 forks source link

Bus Stop JSON File #20

Closed bensim0305 closed 1 year ago

bensim0305 commented 1 year ago

Create a separate JSON file filled with individual bus stop coordinates Checks to see distance between user and closest bus stop, helps with determining what route the user may take (based on closest bus route and what routes run through that stop) meant to use in collaboration with Bus Tracking API

nbriz commented 1 year ago

@bensim0305 here's what u're gonna want to do:

first, modify the package.json file to create a new "script", right now the only script we have is npm run start (which runs our server), but now u'll make a new script npm run bus-stops to create our bus stop database, add something like this to the package.json:

"scripts": {
    "start": "node backend/server.js",
    "bus-stops": "node backend/update-bus-stops.js"
  },

adding that line to the "scripts" section of our package.json allows u to run npm run bus-stops which will then execute ur update-bus-stops.js file... so let's make that next. in the /backend directory of the project create a file called update-bus-stops.js which looks something like this:

const fs = require('fs')
const path = require('path')

// this is example data to test the script,
// u're gonna want to replace this with data
// from the CTA API
const exampleData = [
  { example: 'some data' }
]

// convert the object/array into a JSON string
const data = JSON.stringify(exampleData, null, 2)
// write the data to the file system, into a file called "bus-data.json"
const filepath = path.join(__dirname, '../backend/bus-data.json')
fs.writeFileSync(filepath, data)

in the terminal run npm run bus-stops to test that it works