Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
簡易檔案上傳網站
Slide 2
Slide 2 text
目標 • 可以上傳檔案並給名稱 • 可以清單顯示已經上傳的檔案 • 可以顯示已經上傳的檔案
Slide 3
Slide 3 text
環境 • Windows 7 • Sublime Text 2 • Node.js 0.8.x • Express.js 3.0
Slide 4
Slide 4 text
要求 • 安裝好node 0.8.x • 可以使用npm指令 • 可以使用node指令
Slide 5
Slide 5 text
Step 0: 安裝express 打開終端機 輸入 npm install express –g -g也可以放install前面 -g代表安裝到global 才可以在任何資料夾當作指 令來使用 簡單說就是安裝程式到系統
Slide 6
Slide 6 text
Step 0: 安裝express
Slide 7
Slide 7 text
Step 1: 建立專案 測試express指令
Slide 8
Slide 8 text
Step 1: 建立專案 express -e -c less -s uploadserver
Slide 9
Slide 9 text
Step 2: 安裝所需要的庫 npm install 會自動依照目錄下 的package.json安裝所依賴的 套件到目前目錄(local mode)
Slide 10
Slide 10 text
Step 3: 驗證安裝 node app.js 打開瀏覽器 http://localhost:3000/
Slide 11
Slide 11 text
Step 4: 打開ST2 以資料夾模式開啟
Slide 12
Slide 12 text
Step 5: 編輯bodyParser 修改bodyParser keepExtensions => 保留附檔名 uploadDir => 指定上傳到哪個資料夾
Slide 13
Slide 13 text
Step 6: 接受上傳 var database 模擬一個資料庫 res.redirect(路徑) 回傳302導向其他 網頁
Slide 14
Slide 14 text
Step 7: 修改index view
Slide 15
Slide 15 text
Step 8: 測試看看吧
Slide 16
Slide 16 text
Step 9: 修改index的handler
Slide 17
Slide 17 text
Step 10: 再修改index.ejs
Slide 18
Slide 18 text
Step 11: 測試看看