How should I structure my node/express/mongodb app?

后端 未结 1 1170
孤独总比滥情好
孤独总比滥情好 2021-01-24 14:31

I\'m just curious how people structures their Node.js app?

Usually I create models/ views/ controllers/ and that\'s simple as that. But I\'m kinda new to the Node.js sce

相关标签:
1条回答
  • 2021-01-24 15:01

    For what it's worth, my actual setup is this, until I come up (or find) something clearly better:

    lib
      db
          index.js
          model.js
          ...
      handler
          index.js
          whateverMakesSenseForMyParticularWebSite.js
          ...
      router
          index.js
          model1RestRoutes.js
          model2RestRoutes.js
          iuRoutes.js
          ...
      config.js (or a folder with multiple files if it makes sense)
      server.js (main)
    public
      css
      img
      js
    test
      ...
    views
      ...
    

    So yes, models, views, but I do separate routes and actual handlers' implementation. Decoupling, dependency injection all the way. Way more testable/mockable.

    0 讨论(0)
提交回复
热议问题