我应该如何构建我的节点/ express / mongodb应用程序? [英] How should I structure my node/express/mongodb app?
问题描述
我只是好奇人们如何构建Node.js应用程序?
I'm just curious how people structures their Node.js app?
通常我创建模型/视图/控制器/这很简单。但是我对Node.js的场景很新鲜,我正在尽可能多地学习社区的工作原理。
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!
推荐答案
对于什么是值得的,我的实际设置是这样的,直到我提出(或找到)明显更好的东西:
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.
这篇关于我应该如何构建我的节点/ express / mongodb应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!