express4.x的使用

來源:互聯網
上載者:User

標籤:blog   http   使用   io   strong   檔案   ar   2014   

①、安裝npm install -g  express ②、建立應用express [目錄]會在目錄下產生
  • node_modules, 存放所有的項目依賴庫。(每個專案管理自己的依賴,與Maven,Gradle等不同)
  • package.json,項目依賴配置及開發人員資訊
  • app.js,程式開機檔案
  • public,靜態檔案(css,js,img)
  • routes,路由檔案(MVC中的C,controller)
  • Views,分頁檔(Ejs模板)
 ③、安裝應用依賴npm install ④、apivar app = express()app.use([path],function)  用組件攔截所有請求,包括頁面引用的css、js,這些檔案的請求使用express.static 中介軟體function接受的參數為(req,res,next)或,上一個next(err)下接受(err,req,res,next)app.routeapp.setapp.getapp.paramapp.renderapp.allapp.engineapp.listen ⑤、跟express3.x區別最大區別是middleware不再跟express耦合,如cookie-session  cookieParse  express-session 只保留了express.static express.Router  --------------------------------------------------demo程式碼已上傳github:https://github.com/brucecaigit/express_demo  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.