Getting data from request(req)

Also on Strikingly:


新增 URL (取得 “網址” 內容):2-3. req.method (取得 HTTP Method)



The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on. In this documentation and by convention, the object is always referred to as req (and the HTTP response is res) but its actual name is determined by the parameters to the callback function in which you’re working.

根據常用 req 內容,依來源位置,歸納為 4 類(共5種):

  1. HTML Form (取得 “表單” 內容):req.body
  2. URL (取得 “網址” 內容):
    2-1. req.query、2-2. req.params、2–3. req.method (取得 HTTP Method)
  3. Passport 套件+資料關聯:req.user
  4. Flash Message (提示 User):req.flash(“success_messages”)、req.flash(“error_messages”)
  1. HTML Form:req.body (body-parser 取得 Form 內容)

2–1. URL (取得 “網址” 內容):req.query (取得 URL 中,?後的內容)

2–2. URL (取得 “網址” 內容):req.params (取得 動態路由 [:params ])

2–3. req.method

3. Passport 套件+資料關聯:req.user (取得 User 資料)

4. Flash Message (提示 User):

(1) req.flash 傳遞流程

(2) req.flash 設定方式

(3) 模組化 message 樣板

Equipped with web development, communication, and business analytical skills.