3.3.4.Walkthrough: Creating a Vacations API in Node JS

  • Requirements

    • mlab

      • MongoDB Deployments -> SandBox(free) -> 新增一個叫acmetravel的db

      • Add collection -> 新增一個叫vacations的collection

      • Add database user -> 新增一個叫xxx的user

      • collection-> index -> add index

        • { "name": 1}, 勾選unique

    • source code from github

      • 1.clone repository

        git clone https://github.com/acloudfan/REST-API-Course.git
        cd REST-API-COURSE/
        npm install
      • 2.將資料寫到DB

        • 設定連線字串

          • 到mlab的database頁面下, 複製連線字串

          • 開啟專案, 修改tests/TestDBOps.js的process.env.DB_URI

          • 開啟檢視/ 偵錯主控台/ 終端機, 輸入

               node test/TestDBOps
      • 3.解析程式碼

      • 4.測試API

Last updated

Was this helpful?