0%


Template engine是什麼

模板引擎幫助我們在靜態的html檔案中插入一些動態的變數,使頁面的呈現可以實際與資料互動。模板引擎可以讓介面與資料分離,提升開發的效率使分工更明確,還可以減少重複程式碼的產生。
經過模板引擎的編譯,最終會回傳一般的html檔案到用戶端。

Read more »


將路由設計與應用的進入點分開

通常應用程式會有一個進入點(ex. app.js),藉此驅動其他的程式碼,如果將路由邏輯寫在同個檔案會使單一檔案變得很攏長。幸好express.js提供很方便的方法讓我們簡單使用自己所創造的路由

假設我們將管理員使用的路由寫在admin.js,把給使用者利用的路由寫在shop.js檔案

Read more »


Use nodejs to create web server

1
2
3
4
5
6
7
8
9
//need to include nodejs core moudul 'http'
const http = require('http');
//and then create a listener to receive incomming message and return response object
const server = http.createServer((req, res) => {
console.log(req);
})
//start a process to keep it running to listen for incomming requests. Event loop will keep running
//first argument accept the port which can listen for the requests, if not, then defult port 80 will be used
server.listen(3000);
Read more »


Authentication and Authorization

Authentication Authorization
識別對資料庫來說有效的使用者 識別有效的使用者中他們能做什麼操作
比喻: 例如一家公司的員工被允許進入辦公室 比喻: 公司的員工帳號允許進入辦公室並處理訂單
  • 每個user有專屬的roles,roles包含了一個或多個privileges,而privileges定義了該user能進入那些database和進行那些操作
  • Privileges
    • Resources: 能進入的database、collections
    • Actions: 能進行的操作,例如insert()
  • 資料庫的使用者可以有不同的分工 (Roles),被給予的權限也不一樣(可以避免意外的發生)
Administrator Developer/Your app Data Scientist
能管理資料庫的設定,新增使用者 需要進行新增、刪除、閱讀等操作(CRUD) 需要能夠抓取資料
不需要新增或取用資料 不需要新增使用者或管理資料庫設定 不需要進行新增、刪除等操作
Read more »


Geospatial Data

Geo json架構

  • 必須是一個stucture結構
  • cordinate的第一個屬性是經度,第二個為緯度
1
2
//type與coordinate是一定要有的
db.places.insertOne({name: "Califorina Academy", location: {type: "Point", coordinates: [-122.4724356, 37.7672544]}})
Read more »


啟動mongoDB server

1
2
3
4
5
mongod --dbpath "路徑" //指定資料的存放路徑
mongod --logpath "路徑" //指定log檔的存放路徑(必須是.log),與--dbpath可以一起執行
mongod --port "port" //指定mongodb伺服器的端口
mongod --fork --logpath //讓mongo server在背景執行(不用再另外開個cmd,所以需要指定log路徑來輸出log),只能在Unix和Mac環境使用
net start MongoDB //跟上面一樣讓mongo server在背景執行(windows環境)
  • 終止mongo server
1
net stop MongoDB //windows
  • 使用mongo shell終止mongo server
1
2
use admin //進入admin collection
db.shutdownServer()
Read more »


前言

今年5月底開始在日本工作,日本的許多專業用語是使用片假名發音,或許原本知道的單詞會因此而聽不懂,或是專業用語不是直接從英文轉變,所以此筆記是記錄日本的IT專業用語與中文或英文的對照

Read more »


前言

參考現成的網站模仿實現出一樣的 layout,此次參考的範例為FreeCodeCamp的 學習範例

預覽網頁的整體架構

以下圖片為網站的整體預覽,第一眼大致上得出下一張圖的 html 架構

Read more »