2013年9月5日 星期四

Node.js Taiwan Party 36 筆記 (屬雜記,請忽略我)

這偏是比較屬於個人雜記的部分,請忽略我...(應該只有我自己看得懂...)

Node.js TW 36th Party Note

Topic : Express

Starter need...

* node
* npm
* git
* grunt.js

Express → web base framework

express as cli

- e (ejs) -j(jhtml) -H(hogan)
- jade(as default)
- call help 
- c(css)
- s(session)  

express as css

- -css
- stylus (as default)

* why need template engine -> m”v”c 

run express cli

  • express [-option] [app_name]

folder structure

  • router (like controller + router)
  • static file (at Public folder)
  • app.js is init file

setting in Express

  • app.listen (open port 3000)
  • app.configure (read enviroment variable, ex: develpoment,production…)
  • app.set, app.get
  • app.enable, app.disable (ex, 不啓動view engine)
  • app.use
    • user --> Middleware --> route --> view
      middleware : app.use , will excute every route.
    
  • app.get
  • app.post
  • app.delete
  • app.update
  • app.all
  • app.locals (少用)

req get parameter

  • req.params(抓url)
    • req (像是讀檔案)
    • reponse (寫)
      app.get('/happymen/:id', function(req, res){
          var id = req.params.id;
      }); 
    
  • req.query (取get的資料)
  • req.body
  • req.files
  • req.cookies(read cookie) 重要。

req about HEADER (read only)

  • req.get, req.header (這兩個是相通的)
  • req.is (偵測)
  • req.ip, req.ips
  • req.host (req.subdomains)
  • req.protocol, (req.secure-->'https' == req.protocol; 檢查目前browser是http/https)
  • req.xhr (XMLHttpRequest)
  • Request is READ only in ExpressJS
  • req.status(res.statusCode) 設定header code要給多少(200,400,404,.....)
  • req.clearCookie
  • req.set, res.header
  • req.locals(app.locals is different)
    • life circle is only in url period (<--這好酷)
  • req.redirect (被設成302)
  • req.json, res.send (HEADER:application/json)
  • req.download
  • req.render

Response write data in Express

cross domain access

  • node.js 適合做 api,承載大量的連線 -> know how cross domain access

沒有留言:

張貼留言

若你看的文章,時間太久遠的問題就別問了,因為我應該也忘了... XD

Vue multiselect set autofocus and tinymce set autofocus

要在畫面一進來 focus multiselect 的方式: 參考: https://jsfiddle.net/shentao/mnphdt2g/ 主要就是在 multiselect 的 tag 加上 ref (例如: my_multiselect), 另外在 mounted...