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.
Each of your handlers in
app.js
is doing quite a bit whiledatabase.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 thatstation
is a valid parameter and then it would calldatabase.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.