Claude Code के साथ Deno TypeScript
Claude Code का उपयोग करके deno typescript सीखें। Practical tips और code examples शामिल हैं।
Denodevelopmentको Claude Code से Efficient बनाएं
Denoはsecurityファーストなモダンruntime है।TypeScriptをネイティブサポートし、パーミッションモデルによるsafeな実行環境を提供し है।Claude Code के साथ combineれば、Denoの独自featuresも素早くutilizationでき है।
Projectの初期settings
> DenoでWebアプリをबनाओ。
> Freshframeworkका उपयोग करके、deno.jsonのsettingsअगरて。
// deno.json
{
"lock": false,
"tasks": {
"dev": "deno run -A --watch=static/,routes/ dev.ts",
"build": "deno run -A dev.ts build",
"start": "deno run -A main.ts",
"test": "deno test -A --coverage=coverage",
"lint": "deno lint",
"fmt": "deno fmt"
},
"imports": {
"$fresh/": "https://deno.land/x/[email protected]/",
"$std/": "https://deno.land/[email protected]/",
"preact": "https://esm.sh/[email protected]",
"preact/": "https://esm.sh/[email protected]/"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "preact"
}
}
パーミッションモデルのutilization
Denoはデフォルトでसभीのアクセスを拒否し है।
> file読み取りとnetworkアクセスだけを許可した
> APIserverを作って。最小権限の原則でsettingsして。
// server.ts
// 実行: deno run --allow-net=:8000 --allow-read=./data server.ts
import { serve } from "$std/http/server.ts";
const handler = async (req: Request): Promise<Response> => {
const url = new URL(req.url);
if (url.pathname === "/api/config") {
const data = await Deno.readTextFile("./data/config.json");
return new Response(data, {
headers: { "content-type": "application/json" },
});
}
if (url.pathname === "/api/items") {
const dir = Deno.readDir("./data/items");
const items = [];
for await (const entry of dir) {
if (entry.isFile && entry.name.endsWith(".json")) {
const content = await Deno.readTextFile(
`./data/items/${entry.name}`
);
items.push(JSON.parse(content));
}
}
return Response.json(items);
}
return new Response("Not Found", { status: 404 });
};
serve(handler, { port: 8000 });
Freshでアイランドアーキテクチャ
> Freshのアイランドcomponentでカウンターを作って。
> serverサイドとclientサイドの分離を意識して。
// routes/index.tsx
import Counter from "../islands/Counter.tsx";
export default function Home() {
return (
<div class="max-w-screen-md mx-auto p-4">
<h1 class="text-4xl font-bold">Deno Fresh App</h1>
<Counter start={0} />
</div>
);
}
// islands/Counter.tsx
import { useSignal } from "@preact/signals";
interface CounterProps {
start: number;
}
export default function Counter({ start }: CounterProps) {
const count = useSignal(start);
return (
<div class="flex gap-4 items-center">
<button onClick={() => count.value--}>-</button>
<span class="text-2xl">{count}</span>
<button onClick={() => count.value++}>+</button>
</div>
);
}
testとカバレッジ
// server_test.ts
import { assertEquals } from "$std/assert/assert_equals.ts";
Deno.test("API health check", async () => {
const res = await fetch("http://localhost:8000/api/config");
assertEquals(res.status, 200);
const data = await res.json();
assertEquals(typeof data, "object");
});
Deno.test("file operations with permissions", async () => {
const content = await Deno.readTextFile("./data/config.json");
const config = JSON.parse(content);
assertEquals(config.version !== undefined, true);
});
Deno Deployへのdeploy
# Deno DeployのCLI
deno install -A jsr:@deno/deployctl
# deploy
deployctl deploy --project=my-app --entrypoint=main.ts
Summary
DenoのsecurityモデルとTypeScriptネイティブサポートは、safeで快適なdevelopment体験を提供し है।Claude Code का उपयोग करके、パーミッションsettingsやFreshの独自patternもefficiently習得でき है।TypeScriptdevelopmentのコツやsecurity監査ガイドभी reference के लिए देखें。
Denoके details के लिएDenoofficial documentationをदेखें。
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।