node.js 为什么要使用 Express 而不是 AngularJS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18700334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:34:13  来源:igfitidea点击:

Why would one want to use Express instead of AngularJS?

node.jsangularjsexpress

提问by kamituel

I understand that Express resides on the server and Angular resides on the client but, as far as I know, Angular can do everything that Express can do which is

我知道 Express 驻留在服务器上,而 Angular 驻留在客户端上,但据我所知,Angular 可以做 Express 可以做的一切

  • routing
  • interacting with the database
  • 路由
  • 与数据库交互

It kind of seems like maybe Express is needed in order for an AngularJS app to be served by Node.js but I'm not sure.

似乎需要 Express 才能让 Node.js 提供 AngularJS 应用程序,但我不确定。

So what are the benefits to adding Express to an AngularJS app?

那么将 Express 添加到 AngularJS 应用程序有什么好处呢?

回答by kamituel

There are things which should be done server side (i.e. Express, not Angular), most notably user input validation - Angular, as it's client side, can be tampered.

有些事情应该在服务器端完成(即 Express,而不是 Angular),最值得注意的是用户输入验证 - Angular 作为客户端,可以被篡改。

Also, if you'll ever want to offer access type other than web app (i.e. mobile app), you'll probably need an API anyway - Express can do this, Angular don't.

此外,如果您想提供 Web 应用程序(即移动应用程序)以外的访问类型,则无论如何您可能都需要一个 API - Express 可以做到这一点,而 Angular 则不能。

Finally, database access - usually Angular app will need to connect to some kind of backend to perform CRUD operations. You'll either go with hosted DB like Firebase, or you'll end up using your own database. Latter scenario is more popular and you'll need Express (or similar) for that.

最后,数据库访问 - 通常 Angular 应用程序需要连接到某种后端来执行 CRUD 操作。您要么使用像 Firebase 这样的托管数据库,要么最终使用自己的数据库。后一种情况更受欢迎,为此您需要 Express(或类似的)。

回答by dark_ruby

Express and AngularJS do not mutually exclude one another, they serve different purpose - in fact it's perfectly fine to use both - express for all your serverside logic, and Angular for client side logic.

Express 和 AngularJS 并不相互排斥,它们服务于不同的目的——事实上,两者都可以使用——express 用于所有服务器端逻辑,而 Angular 用于客户端逻辑。

回答by zs2020

Express can be used to host the APIs for AngularJS's service/factory to consume. You can consider AngularJS as MVCand the API on Express as SOA.

Express 可用于托管 AngularJS 的服务/工厂使用的 API。您可以将 AngularJS 视为MVC,将 Express 上的 API 视为SOA.

回答by Chandermani

There is lot of stuff that one wants to control from server. And that is the place where the server side frameworks come into picture.

有很多东西想要从服务器控制。这就是服务器端框架出现的地方。

An web app is not just some html pages linked together. There are lot of other things that needs to be implemented

Web 应用程序不仅仅是链接在一起的一些 html 页面。还有很多其他的东西需要实现

  • Model validation.
  • Keeping model consistent. Remember multiple users can access the same model at any give time and even change it.
  • Controlling resource access.
  • Triggering workflows.
  • Business Logic.
  • 模型验证。
  • 保持模型一致。请记住,多个用户可以随时访问同一个模型,甚至可以更改它。
  • 控制资源访问。
  • 触发工作流。
  • 商业逻辑。

and other such thing require a server framework. So as mentioned earlier the client side frameworks like AngularJS complement server side frameworks.

和其他这样的事情需要一个服务器框架。因此,如前所述,像 AngularJS 这样的客户端框架补充了服务器端框架。