在路由中加入 middleware,讓伺服器接到瀏覽器傳來的 HTTP request時,會自動把資訊記錄到 server log 中。 當回應伺服器後馬上存入回應的時間並印出req-res cycle之間的時間差。
- server log會記錄以下:
- 時間戳記 (time-stamps) - 以當地時間 (台北) 顯示
- HTTP request Method
- URL
- 中間req-res cycle的時間差
- Node.js
- express
$git clone https://github.com/ywcwy/middleware_req-res_cycle.git
After download,
$cd middleware_req-res_cycle // to install the following Packages under this directory
$npm init -y // create and initialize package.json directory
$npm install // install all the Packages
$npm run dev
App running on port 3000 // if start working, termianl will show this message