用于 REST 的 Node.js Express? Express 中有控制器吗?

发布于 2024-12-09 20:14:10 字数 902 浏览 0 评论 0原文

我目前正在为有限(本地)目标开发一个社区(如轻量级“社交网络”)。 这是第一个 SEO 无关紧要的项目,我可以愉快地排除 no-js 用户。这就是为什么我出于教育原因考虑重新开始该项目并编写我的第一个完全使用 Javascript 构建的网站以及我的第一个 Node 应用程序

到目前为止的详细信息:

浏览器:jQuery,也许JavaScriptMVC(JavaScriptMVC 有一些我不喜欢的东西(比如路由),也许我写了自己的小 MVC 或你知道更适合的框架吗?

服务器:Node.JSExpress框架,(可能是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

给不了的爱 2024-12-16 20:14:10

您见过 Swagger 吗? Node.js 中提供的 API 服务器,带有自动化 UI 生成器

Swagger
(来源:wordnik.com

Have you seen Swagger? An API server available in Node.js with an automated UI Generator.

Swagger
(source: wordnik.com)

匿名。 2024-12-16 20:14:10

要回答您的主要问题,是的,Express 中有控制器。它们更类似于 Sinatra(express 是根据 Sinatra 而不是 Rails 建模的)。我的意思是它们是到您定义的路由的轻量级方法映射。

浏览器:jQuery,也许 JavaScriptMVC(有些东西我不知道)
就像 JavaScriptMVC (比如路线),也许我自己写
MVC 很少,或者您知道更适合的框架吗?

我会选择 spine.jsbackbone.js 个人。

Express 看起来确实不错,但我缺少 MVC。我找不到任何
实现 mvc 并基于 Express 构建的项目。有没有理由
为此? Express 中的路由很好,但我需要一种传播代码的方法
跨多个文件(我猜控制器是最好的方式,
应用程序不会很小,而且我需要它可维护)

您可以将文件分散到您想要的地方。我在此处回答了这个问题

该应用程序将或多或少完全基于 AJAX (json)
请求。 Express 是此类应用程序的正确框架吗?
反正?我认为编写这个项目的最好方法是公开一个 json
然后 Web 应用程序可以通过 AJAX 查询 REST api
以及通过移动设备应用程序(我也将编写)。在我的
意见 Express 的路线系统非常适合 REST。但随意
推荐其他框架。

我还没有在节点中构建单页应用程序,但据我所知,几乎每个人似乎都在使用 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.

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?

I'd go with spine.js or backbone.js personally.

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)

You can spread files out all you want. I answered this here.

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.

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.

南街女流氓 2024-12-16 20:14:10

您可以查看 Sails。其结构基于Rails。

You could check out Sails. Its structure is based on Rails.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文