1. 了解如何處理 CORS

[教學] CORS 是什麼? 如何設定 CORS? - Shubo 的程式開發筆記

Express cors middleware (expressjs.com)

這次直接用以下用法開放全網域,不研究其他用法

Simple Usage (Enable All CORS Requests)

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

app.get('/products/:id', function (req, res, next) {
  res.json({msg: 'This is CORS-enabled for all origins!'})
})

app.listen(80, function () {
  console.log('CORS-enabled web server listening on port 80')
})
  1. PUT V.S. PATCH

筆記下來,因為助教要我去理解箇中差異 XD

POST vs PUT vs PATCH: Make the right Restful API decision | by Jason Byrne | Medium

  1. 解構賦值 前後形態要一致才能解構 ex: 前後都用object 或前後都用array

    Promise.all()要解構 因為Promise.all裡面是Array 所以要拿promise完的值要用array ex: const [ user, useremail ] = await Promise.all([ User.findByPk, User.findOne ])

  2. sequelize資料庫回傳值toJSON()

    這是指資料庫回給後端的部分 toJSON()只能用在obiect 所以我們在getUsers拿所有資料的時候會從資料庫得到一個Array Array裡面每一項的值都是一個Object 通常我們會用一個變數去接這一個Array,再每一個object做toJSON() ex: const users = usersFind.map(user => ({ ...user.toJSON() }))

  3. assert套件判斷並回傳訊息 https://nodejs.org/api/assert.html#assertvalue-message 用法:

const assert = require('assert')

assert( 條件判斷, 條件不成立回傳字串訊息 )

ios

"scripts": {
    "start": "NODE_ENV=development&& node app.js",
    "dev": "NODE_ENV=development&& nodemon app.js",
    "test": "mocha test --exit --recursive --timeout 5000"
  },