用于 REST 的 Node.js Express? Express 中有控制器吗?
我目前正在为有限(本地)目标开发一个社区(如轻量级“社交网络”)。 这是第一个 SEO 无关紧要的项目,我可以愉快地排除 no-js 用户。这就是为什么我出于教育原因考虑重新开始该项目并编写我的第一个完全使用 Javascript 构建的网站以及我的第一个 Node 应用程序。
到目前为止的详细信息:
浏览器:jQuery,也许JavaScriptMVC(JavaScriptMVC 有一些我不喜欢的东西(比如路由),也许我写了自己的小 MVC 或你知道更适合的框架吗?)
服务器:Node.JS,Express框架,(可能是socket.io或nowjs以获得更多功能)
到目前为止我有几个问题。我知道最好问一个问题,但或多或少有一些联系:
Express 看起来确实不错,但我缺少 MVC。我找不到任何实现 mvc 并基于 Express 构建的项目。这是有原因的吗? Express 中的路由很好,但我需要一种方法来跨多个文件传播代码(我猜控制器将是最好的方法,应用程序不会很小,而且我需要它可维护)
应用程序将或多或少<完全基于AJAX(json)请求。 Express 是否是此类应用程序的正确框架?我认为编写这个项目的最佳方法是公开一个 json REST api ,然后可以通过 AJAX 的 Web 应用程序和移动设备应用程序(我也将编写)来查询它。在我看来,Express 的路线系统非常适合 REST。但请随意推荐其他框架。
I'm currently developing a community (like a lightweight "social network") for a limited (local) target.
This is the first project where SEO doesn't matter and where I can happily exclude no-js users. That's why I'm thinking to start the project over and write my first site that is completely build with Javascript and my first Node application for educational reasons.
Details so far:
Browser: jQuery, maybe JavaScriptMVC (there are some things I don't like about JavaScriptMVC (like the routes), maybe I write my own little MVC or do you know a better suited framework?)
Server: Node.JS, Express framework, (maybe socket.io or nowjs for further features)
I got a few questions so far. I know it's better to ask a single question but there are more or less connected:
Express looks really nice but I'm missing MVC. I couldn't find any project that implements mvc and is build on Express. Is there a reason for that? Routing is nice in Express but I need a way to spread code across multiple files (controllers would be the best way I guess, the application won't be small and I need it maintainable)
The application will be more or less completely based on AJAX (json) requests. Is Express the right framework for such applications, anyway? I think the best way to write this project is to expose a json REST api which can then be queried by the web application over AJAX and by a mobile device app (which I'm also going to write). In my opinion Express' route system is quite suited for REST. But feel free to recommend other frameworks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您见过 Swagger 吗? Node.js 中提供的 API 服务器,带有自动化 UI 生成器。
(来源:wordnik.com)
Have you seen Swagger? An API server available in Node.js with an automated UI Generator.
(source: wordnik.com)
要回答您的主要问题,是的,Express 中有控制器。它们更类似于 Sinatra(express 是根据 Sinatra 而不是 Rails 建模的)。我的意思是它们是到您定义的路由的轻量级方法映射。
我会选择 spine.js 或 backbone.js 个人。
您可以将文件分散到您想要的地方。我在此处回答了这个问题 。
我还没有在节点中构建单页应用程序,但据我所知,几乎每个人似乎都在使用 socket.io< /a> 与 骨干。这并不是说您不能,只是您会通过这种方式找到更多示例。
To answer your primary question, yes there are controllers in Express. They are more akin to Sinatra (express is modeled after Sinatra rather than Rails). By that I mean they are light-weight method mappings to routes you define.
I'd go with spine.js or backbone.js personally.
You can spread files out all you want. I answered this here.
I haven't built a 1 page app yet in node but from what I can tell, almost everyone seems to be using socket.io with backbone. That's not to say you can't, just that you'll find more examples that way.
您可以查看 Sails。其结构基于Rails。
You could check out Sails. Its structure is based on Rails.