老师对我们的建议:学习MEAN架构最好的办法就是官网和教程。如果觉得自己英文还可以的话,直接看官网是最好的手段,技术文章用的英语都是很浅显的,而且不部分看了代码就清楚了。
官网中给了直接从GitHub中获取的方法,感觉更加简单。
$ git clone https://github.com/linnovate/mean.git
$ cd mean
$ npm install && npm start
简单概括下官网的内容:
1,MEAN.io v2(目前最新版)确保安装了
- Node.js higher than 6.x
- MongoDB
- Git
- npm
2,一个用来测试MongoDB的网站 https://mlab.com。安装MEAN还需要Python?,这点老师没讲过,也许是我们用backbone替换了A,明天可以问一下。然后还有几个常见错误,跟我之前遇见的都不同。
3,最新的也是变化最大的报告介绍了几个还未完成(?)的新特性,更新Angular ,GraphQL,BIT(开发者说他放弃MEANIO,而选择BIT?)搜索了一下原来是MEAN的开发者离开了MEAN.io创建了MEAN.js。
那么也就是说我之前看的都不是现在的要学的MEAN。。。
重新看MEAN.js官网,配置什么的都一样,就是项目地址变为
https://github.com/meanjs/mean.git
下面来看下结构:
Folders
config
1,config/assets
基本作用是告诉应用程序需要知道哪些assets文件以及在哪里可以找到它们。
2,config/env
environment
3,config/lib
库模块
modules As described in the AngularJS Developer Guide, "you can think of a module as a container for the different parts of your app".
modules/*/client
客户端代码和与特定模块相关的相关文件。
modules/*/server
与特定模块相关的服务器端代码和相关文件。
modules/*/tests
代码和相关文件用于验证及验证与模块相关的其他代码。
public
包含从应用程序源代码构建的元素以及应用程序所需的第三方外部库。public/lib
应用程序和Bower引入的外部库将放置在此处。
public/dist
最终程序
scripts
各种帮助脚本
Express
web框架 config/lib/express.js
Exposing Config Properties
app.locals
在这里设置的对象类似全局变量
res.locals
局部变量
Routing
路由,看下图

除url还有最常见的四种请求方法是GET,POST,PUT和DELETE。
路由的结构还是要记一下的 app.METHOD(PATH, HANDLER)
- app is an instance of Express;
- METHOD is an HTTP request method;
- PATH is a path on the server; and
- HANDLER is the function executed when the route is matched.
Middleware
middleware are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle.
中间件的顺序决定加载的顺序。??When your app starts up, the order in which middleware functions are loaded determines the order in which they’ll be executed.
Server Tests
Mocha tests 还要了解一下。使用断言和每个实体都有自己的测试文件。不是很懂。
然后是写的顺序:
Writing Tests
There are a few common steps we use to test an entity:
- In the beforeEach or before functions take care of prerequisites and create the objects you are about to use in your tests.
- For each test start with a describe function to indicate which method is being tested.
- Next, add your scenario tests using the it function.
- In the it function run the tests functionality and use should to assert what the end result should be.
- Finally use after or afterEach functions to finalize your tests and clear the test database.
Passport
身份验证机制,可以使用本地喝一些第三方的身份验证。
然后就是Angular,就先不看了。
不知道MEAN.js的blog是不是被墙了,怎么也打不开。http://blog.meanjs.org/
298

被折叠的 条评论
为什么被折叠?



