[英]Can Express routes be used as MVC Controllers in Node.JS Apps?
I have been playing around for a bit on Nodejs, so forgive me if my question might look stupid. 我已经在Nodejs上玩了一段时间,所以如果我的问题看起来很愚蠢,请原谅我。
When I setup a new nodejs app with express, I noted that it created a folder /routes that basically does what it suggests. 当我使用express设置一个新的nodejs应用程序时,我注意到它创建了一个文件夹/ routes,基本上可以完成其建议的工作。
Now, is it ok to use said file(s) as the Controllers for my app? 现在,可以将所述文件用作我的应用程序的控制器吗?
I think so. 我认同。 Because role of a route in express is to decide what to do when a certain request comes, such as getting data from a model or rendering a view with some data and this is what controllers do, right?
因为路由在express中的作用是决定当某个请求到来时该怎么办,例如从模型中获取数据或使用某些数据呈现视图,而这正是控制器要做的,对吧?
You can see in official examples that routes are actually placed in a folder named conrollers
. 您可以在官方示例中看到,路由实际上位于名为
conrollers
的文件夹中。
https://github.com/visionmedia/express/blob/master/examples/mvc/controllers/pet/index.js https://github.com/visionmedia/express/blob/master/examples/mvc/controllers/pet/index.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.