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

女生的网名这么多〃 提交于 2019-12-31 04:32:07

问题


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 scene and I'm trying to learn as much as I can about how the community works.

Any answer is welcome, thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/9607947/how-should-i-structure-my-node-express-mongodb-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!