简体   繁体   中英

Node express mongoose directory structure best practices

I found this library structure for express app, but with mongoose the model library has different use. Where i put my schemes? 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) ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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