# 初始化 nodejs 專案 ``` npm init -y ``` # 安裝 typescript 相關套件 ``` npm i express npm i -D typescript @types/node @types/express npm i -D ts-node nodemon ``` # 初始化 typescript 設定檔 ``` npx tsc --init ``` # 修改 tsconfig.json ```json= { "outDir": "./dist" } ``` ## app.ts ```typescript= mkdir src touch src/app.ts ``` ```typescript= import express from 'express'; export const app = express(); app.get('/', (req, res) => { res.send('hello typescript'); }); export default app; ``` ## index.ts ```shell= touch index.ts ``` ```typescript= import { app } from './src/app'; app.listen(3000); ``` # 修改npm script ```javascript= scripts: { "dev": "nodemon index.ts", "build": "tsc" } ``` ## 執行npm script ```shell= npm run dev npm run build ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up