經過Express命令建立項目css
Express 是一個簡潔而靈活的 node.js Web應用框架, 提供了一系列強大特性幫助你建立各類 Web 應用,和豐富的 HTTP 工具。html
使用 Express 能夠快速地搭建一個完整功能的網站。node
Express 框架核心特性:git
能夠設置中間件來響應 HTTP 請求。web
定義了路由表用於執行不一樣的 HTTP 請求動做。express
能夠經過向模板傳遞參數來動態渲染 HTML 頁面。npm
先看下Express的命令模式:json
D:\nodejs_project\webappdemo>express -h Usage: express [options] [dir] Options: --version output the version number -e, --ejs add ejs engine support --pug add pug engine support --hbs add handlebars engine support -H, --hogan add hogan.js engine support -v, --view <engine> add view <engine> support (dust|ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade) -c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css) --git add .gitignore -f, --force force on non-empty directory -h, --help output usage information
1) jade模版引擎瀏覽器
D:\nodejs_project>express app
express默認以jade做爲模板引擎,模板文件爲.jade類型;jade的語法與html有較大差別,對縮進也是要求嚴格的sass
jade模版引擎,語法簡潔,Jade強制的縮進格式能凸顯html的結構; ade專爲HTML設計,所以能夠作許多傳統模板作不到的專門針對html的優化。舉個幾個簡單的例子: 1). 決定如何輸出屬性(當屬性賦值爲null/false時不輸出屬性,爲true時只需屬性不須要值,這在傳統模板裏寫起來很麻煩、代碼難看易出錯) 2). 自動產生well-formed結構(甚至可決定是否要輸出結束標籤,而傳統模板理論上也作不到這點,除非引入額外的html parse或tidy) 3). 換行處理,避免產生額外的空白節點 4). 對輸出的變量自動進行特殊字符的encode
2) ejs模版引擎
D:\nodejs_project>express webappdemo -e
在項目名稱的後面添加 -e 那麼建立出來的模板引擎就是.ejs類型,語法是與html相同的
D:\nodejs_project\webappdemo>npm install npm notice created a lockfile as package-lock.json. You should commit this file. added 57 packages in 17.975s
D:\nodejs_project\webappdemo>npm start > webappdemo@0.0.0 start D:\nodejs_project\webappdemo > node ./bin/www GET / 200 10.670 ms - 207 GET /stylesheets/style.css 200 5.965 ms - 111