老師對我們的建議:學習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/