What's the best way to separate the different tiers of an express application, so that my app.js file doesn't get crammed full of functions? I'm coming from a Java world, so I typically have my models, business logic and DAO code in separate tiers.
The other question, that has been bothering me: how do I open a connection to a DB in app.js and then share that among the various pieces of code that need access to it? Not the routed functions, but the business logic modules.
See this project as separate files as follows:
https://github.com/lethus/popbroker
routes.js - Here we put the routes, usually referenced to controllers
models.js - Model here you put the functions of MongoDB
forms.js - You work the validation of objects
controllers / users.js - That would be something like java UI, here we call the models.js and do the insert, update, list, Finds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With