Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating models, logic and DAOs in express/node.js

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.

like image 359
mlaccetti Avatar asked Feb 14 '12 02:02

mlaccetti


1 Answers

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

like image 182
Damon Abdiel Avatar answered Nov 06 '22 22:11

Damon Abdiel