5 分钟上手
安装 Deno,运行一个最小权限的 TypeScript HTTP 服务并执行测试
1. 安装并验证
macOS / Linux
curl -fsSL https://deno.land/install.sh | sh
deno --version
Windows
irm https://deno.land/install.ps1 | iex
deno --version
Docker
docker run --rm denoland/deno:latest deno --version
2. 初始化并运行
deno init --serve hello-deno
cd hello-deno
deno task dev
deno init --serve 会创建 deno.json、服务入口和测试。模板服务需要监听网络;如果你手写入口,可明确运行:
Deno.serve((_request) => Response.json({ ok: true }));
deno run --allow-net main.ts
curl http://localhost:8000
# {"ok":true}
3. 添加测试
import { assertEquals } from "jsr:@std/assert";
Deno.test("adds two numbers", () => {
assertEquals(2 + 3, 5);
});
deno test
4. 提交前门禁
deno fmt --check
deno lint
deno check **/*.ts
deno test
官方依据:Get started、Installation、Testing。