I'm currently writing my first Node application. It's the back end for a single page web app. As the app expands, the biggest trouble I'm having is organising the code that interacts with the database.
I essentially have one big file with functions that execute SELECT queries and pass that data on to another function that processes the resulting data if needed. There's another file that takes in data from the user, validates it, and performs any INSERT/UPDATE queries.
Keeping it all in one place seems sensible as many of these functions are used in different spots throughout the code, but as the file expands in size it's getting harder and harder to work with. It's now exceeded 1100 lines, which is almost 1/3rd of the total app.
Is there a better structure than this for fetching and processing data? Is the best solution to this problem to break out related queries into their own, smaller files? If so, how granular should the files be (e.g. 10 queries in one file or a single query in one file)?
Aucun commentaire:
Enregistrer un commentaire