简体   繁体   English

Node express mongoose 目录结构最佳实践

[英]Node express mongoose directory structure best practices

I found this library structure for express app, but with mongoose the model library has different use.我为 express 应用找到了这个库结构,但是对于 mongoose,模型库有不同的用途。 Where i put my schemes?我把我的计划放在哪里? https://www.terlici.com/2014/08/25/best-practices-express-structure.html https://www.terlici.com/2014/08/25/best-practices-express-structure.html

project/
  controllers/
    comments.js
    index.js
    users.js
  helpers/
    dates.js
  middlewares/
    auth.js
    users.js
  models/
    comment.js
    user.js
  public/
    libs/
    css/
    img/
  views/
    comments/
      comment.jade
    users/
    index.jade
  tests/
    controllers/
    models/
      comment.js
    middlewares/
    integration/
    ui/
  .gitignore
  app.js
  package.json

You put your Schemas in the models folder.Using mongoose you can then create the model for each Schema in its file, and then export the model.您将架构放在模型文件夹中。使用猫鼬,您可以在其文件中为每个架构创建模型,然后导出模型。 You can also exports some functions operating on your models in the same file, such as Model.findAll(), Model.findById(id) ...您还可以在同一文件中导出一些对您的模型进行操作的函数,例如 Model.findAll()、Model.findById(id) ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM