简体   繁体   English

MEAN环境中的Node.js程序结构

[英]Node.js program structure in MEAN environment

I'm currently working on a web application based on the popular MEAN stack (MongoDB, Express, AngularJS and Node.js). 我目前正在基于流行的MEAN堆栈(MongoDB,Express,AngularJS和Node.js)开发Web应用程序。 As I am still struggling with some aspects of node.js, I would like to ask for your advice and opinion on a major architecure decision of mine. 由于我仍在努力处理node.js的某些方面,因此,我想就我的一项重大体系结构决策征询您的意见和建议。

As I found Jade rather ugly (notation-wise) and did not want the server to render webpages (for cpu power saving reasons), I chose to always send back prepared html files/templates. 当我发现Jade非常丑陋(从符号上讲)并且不希望服务器呈现网页(出于cpu省电的原因)时,我选择始终发送回准备好的html文件/模板。

Example: 例:

app.get('/', function(req, res) {
  res.sendfile("public/index.html");
});

On the client side, I then initiate further Angular-JSON based communication to realize REST webservices to instantly get and fill in the needed data. 然后,在客户端,我进一步发起基于Angular-JSON的通信,以实现REST Web服务,以立即获取并填写所需的数据。 Any reasonable arguments against this approach or maybe good points why I should be using a render engine on the server side? 任何反对这种方法的合理论点,或者也许是好的一点,为什么我应该在服务器端使用渲染引擎?

Besides, does anyone know a good online tutorial for a multipage web application featuring user registration/validation, authentication process, rest webservices and so on? 此外,没有人知道多页Web应用程序的良好在线教程,该应用程序具有用户注册/验证,身份验证过程,其余Web服务等功能吗? Something newbies can take a look at to get a feeling of how to structure a medium to large sized node.js application well? 新手可以看一下,以了解如何很好地构建中型到大型的node.js应用程序? I've been googling for days now but feel that all tutorials I found were always missing essential ingredients or were rather "elementary". 我已经搜寻了好几天,但是觉得我发现的所有教程总是缺少基本要素,或者说是“基本”的。

Thanks in advance. 提前致谢。 Igor 伊戈尔

I started with Node.js like 2 month ago and now I am starting a project following this same approach. 我从2个月前开始使用Node.js,现在我正在按照相同的方法启动一个项目。

In the same way, I am not using a "render engine", mainly because I am planning to use my client code (angular) to create a hybrid application using cordova (phoneGap). 同样,我没有使用“渲染引擎”,主要是因为我计划使用客户端代码(角度)来使用cordova(phoneGap)创建混合应用程序。

I learned a lot from the tutorials of Node.js in Pluralshigh: 我从Pluralshigh的Node.js教程中学到了很多东西:

Finally, regarding security, "Passport" is a great library to implement authentication. 最后,关于安全性,“护照”是一个很好的实现身份验证的库。

btw: I am using Token-Based Authentication. 顺便说一句:我正在使用基于令牌的身份验证。

And the answer to "how integrate Passport with tokens", I found it here: 关于“如何将Passport与令牌集成在一起”的答案,我在这里找到了:

passport-local with node-jwt-simple 本地护照和node-jwt-simple

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM