Structure of Express/Mongoose app

后端 未结 5 1404
醉酒成梦
醉酒成梦 2021-02-10 09:00

How should I go about structuring my express/mongoose application, so that I can use my schemas, models, routes and the functions that get called when those routes are hit?

5条回答
  •  旧时难觅i
    2021-02-10 10:00

    Take a look at my express_code_structure example repo for my recommendations on a module filesystem organization.

    However, your code samples above are major MVC violations. Do not pass the app instance to your model. Do not have your model have any awareness of req objects or HTTP services whatsoever. Model: data structure, integrity, persistence, business logic, and nothing else. Routes should be defined in entirely separate .js files from your models.

提交回复
热议问题