Let Express.js support TypeScipt

目前有三個ts檔案,分別為custom.d.ts, routes.ts, index.ts 當各別下tsc custom.d.ts, tsc routes.ts, tsc index.ts, 與在資料夾的根目錄下npx tsc的結果不一樣。當各別下時,需在routes.ts的開頭加入/// ,且當下tsc index.ts時會出現錯誤:index.ts:2:8 – error TS1259: Module ‘”/mnt/c/cmder/Project/Book/Node.js/sample-express/node_modules/@types/express/index”‘ can only be default-imported using the ‘esModuleInterop’ flag 2 import express, { …

TypeScript Built-in Types

Primitive JavaScript Types The union Type The array Type The tuple Type The any Type The void Type The object Type Custom Types and interface

traditional() vs arrow()

分析 traditional() 方 理解 this 綁定 等價於: javascript複製編輯console.log(scopeOf.traditional()); // 相當於 scopeOf.traditional.call(scopeOf); 因此: javascript複製編輯this === scopeOf; // ✅ this 綁定到 scopeOf this.scope === “defining scope”; // ✅ 回傳 “defining scope” 分析 …

Node.js

Node.js is a JavaScript runtime environment. First, Install the Node.js in your computer system. Windows: Linux: use nvm to manage the different node version The default package manager for Node.js …

產生https所需要Key.pem與Cert.pem檔案

openssl genpkey -algorithm RSA -out private.pem openssl req -new -key private.pem -out mydomain.csr openssl x509 -req -days 365 -in mydomain.csr -signkey private.pem -out certificate.pem 最終得到的private.pem與certificate.pem

基本的Node與NPM使用方式

首先安裝 NVM (Node Version Manager),由它安裝及管理Node的開發環境版本。 使用npm init -y 建立一個node的專案 使用npm install express, request –save安裝此次所使用到的express.js與request Package. 建立server.js文件 修改package.json 使用npm start運行程式server.js 使用postman進行測試