fac-14 / OSCEBossKey

Weeks 13-16 > Tech for Better project: An app to help medical students revise for their exams
https://oscebosskey.herokuapp.com/
MIT License
3 stars 2 forks source link

Separate out concerns in app.js #146

Open tbtommyb opened 5 years ago

tbtommyb commented 5 years ago

Each of your handlers in app.js is doing quite a bit while database.js is only wrapping Airtable.

A good practice is to try and expose as little as possible of each bit of your app. So e.g. app.get("/api/get-station/:station" would be responsible for validating that station is a valid parameter and then it would call database.getStation(station) and returning either JSON or a useful error. Within the database module you'd have functions that would access the various things from Airtable.

This means that the server is only responsible for communicating with the client and all of the business logic is separate. Ideally the business logic shouldn't 'know' that it's in a web server. This also means you can change database or web server without having to rewrite everything.