[指南] Nodejs + TypeScript + Express 打造你的簡易 API Server

章節連結

過往都是透過 Vue-Cli 或是 Vite 提供的安裝工具快速安裝 TypeScript 和前端框架一同使用。這次來試用自行一步步的安裝流程,並搭配 ESLint 和 Axios 來一同使用。
nodejs-typescript-express-api-server


重點過程

1. 用 npm init -y 在一個資料夾根目錄中建立 package.json 的文件
2. 將 @types/express, @types/node, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, eslint, ts-node, typescript 安裝在 devDependencies 中
3. 將 axios, cross-env, dotenv, express 安裝在 dependencies 中
4. 設定 tsconfig 檔,其中 outDir 預設值建議要給,否則編譯後的 js 檔會直接產在你的 ts 同層目錄下
5. 設定 .eslintrc.js 檔,這是整份檔案中,唯一使用 module.exports 的
6. 腳本中的指令檔為了間容各種 OS,需要使用 cross-env

程式碼

https://github.com/andy922200/express-ts-template

按讚加入粉絲團

延伸閱讀