Upload File with Unique File Name and Extension
We can get file extension on the server and set unique file name and extension by Multer.
戦わなければ、勝てない
We can get file extension on the server and set unique file name and extension by Multer.
We can provide unique file name by Client and specify this name to Multer.
When we POST file to the server, we can also POST other data.
We can upload file with original file name and provide downloadable link by static web server.
Multer default changes the file name of uploaded files. If we want to keep the original file name, we have to write some code.
We can use Multer
with Express
to upload files from the browser and receive files from the server.
Not only using Express as API Server but also Web Server for static HTML.
If we want to use Microservice architecture, we will build Nginx, Express, PostgreSQL images first, and then use Docker Compose to run Nginx, Express, PostgreSQL at once.
If we can run Express by Docker on the local machine, we can run Express by Docker on AWS EC2.
If we want to use Express DELETE to delete data from MSSQL, we can use Knex and Tedious to connect.
If we want to use Express PUT to edit data to MSSQL, we can use Knex and Tedious to connect.
If we want to use Express POST to add data to MSSQL, we can use Knex and Tedious to connect.
If we want to use Express GET to return data from MSSQL, we can use Knex and Tedious to connect.
If we want to use Express DELETE to delete data from PostgreSQL, we can use Knex and Node-postgres to connect.
If we want to use Express PUT to edit data to PostgreSQL, we can use Knex and Node-postgres to connect.
If we want to use Express POST to add data to PostgreSQL, we can use Knex and Node-postgres to connect.
If we want to use Express GET to return data from PostgreSQL, we can use Knex and Node-postgres to connect.
若要使用 Microservice 架構,則會各自將 Vue 與 Express 包成 Docker Image,然後使用 Docker Compose 一次啟動 Vue 與 Express,此時 Express 會包在 Docker 內部網路,Vue 需使用 Nginx 的 Reverse Proxy 才能連上 Express。
若要使用 Microservice 架構,則會各自將 Vue 與 Express 包成 Docker Image,然後使用 Docker Compose 一次啟動 Vue 與 Express,此時 Express 會包在 Docker 內部網路,Vue 所需的 HTTP Service 與 Reverse Proxy 也使用 Express 提供。
Vue CLI 提供 yarn build
將 HTML / CSS / JS 編譯到 dist
目錄下,我們可再利用 Node + Express 當 Web Server,自行擴充 NPM Script,最後只要下 yarn docker
就可一鍵建立 Docker Image。
Node 本身已提供 HTTP 服務,可用來開發 API,可自行擴充 NPM Script,最後只要下 yarn docker
就可一鍵建立 Docker Image。
若要刪除資料,可使用 DELETE 透過 Params 傳遞 ID。
若要修改資料,可使用 PUT 透過 Body 傳遞,並將 ID 在 URL 以 Params 表示。
若要新增資料,可使用 POST 透過 Body 傳遞,只要使用 express.json
所回傳 Middleware,就可利用 req.body
讀取。
若要以 Query String 傳遞資料,可透過 req.query
讀取。
若要將 ID 放在 URL 內,可透過 req.params
取得。
若要回傳不同的 HTTP Status Code,可使用 res.status
或 res.sendStatus
。
開發 API 時,到底要追傳什麼 HTTP Status Code 一直是 Developer 不可避免課題,可藉此 Flowchart 幫助決策。
Node 除了能實現 HTTP Server 外,只要加上 Http-proxy middleware,也能輕易實現 Proxy Server。