Claude Code के साथ Deno TypeScript: permissions, deno.json और Deno.serve
Claude Code से Deno ऐप बनाएं: कम-से-कम permissions, deno.json tasks, Deno.serve और built-in fmt/lint/test के साथ।
Deno में पहले permissions सोचें
Deno JavaScript और TypeScript चलाने वाला runtime है। Runtime का मतलब वह आधार है जो आपका कोड execute करता है। Deno की खास बात यह है कि यह secure by default है: file access, network, environment variables और external command तब तक बंद रहते हैं जब तक आप permission नहीं देते। आधिकारिक संदर्भ के लिए Security and permissions देखें।
Claude Code Deno प्रोजेक्ट में server, tests, deno.json और review checklist जल्दी बना सकता है। लेकिन अगर prompt अस्पष्ट है, तो आउटपुट में -A, Node.js वाली आदतें या गैरजरूरी dependencies आ सकती हैं। इसलिए prompt में runtime, API, permissions और verification command साफ लिखें।
शुरुआती शब्दावली: permission का मतलब है program को किन resources तक पहुंच की अनुमति है। deno task deno.json में लिखा named command है। Formatter code style ठीक करता है, linter संभावित गलती पकड़ता है, और test runner Deno.test() चलाता है। Deno में ये tools built-in हैं। आगे के लिए API development, testing strategies और TypeScript tips भी उपयोगी हैं।
Claude Code को ऐसा prompt दें
Deno में छोटी JSON API बनाइए।
Deno.serveइस्तेमाल करें, Express नहीं।deno.jsonमेंdev,start,fmt,lint,testऔरchecktasks बनाएं।-Aइस्तेमाल न करें। सिर्फ--allow-net=127.0.0.1:8000,--allow-read=./dataऔर--allow-write=./dataदें। TestsDeno.test()से लिखें।
यह prompt Deno की official pages configuration, deno task, Deno.serve और deno test से मेल खाता है।
deno.json में tasks
{
"tasks": {
"dev": "deno run --watch --allow-net=127.0.0.1:8000 --allow-read=./data --allow-write=./data server.ts",
"start": "deno run --allow-net=127.0.0.1:8000 --allow-read=./data --allow-write=./data server.ts",
"fmt": "deno fmt",
"lint": "deno lint",
"test": "deno test",
"check": "deno fmt --check && deno lint && deno test"
},
"fmt": {
"lineWidth": 100,
"semiColons": true
},
"lint": {
"rules": {
"tags": ["recommended"]
}
},
"imports": {
"@std/assert": "jsr:@std/assert"
}
}
check task Claude Code और CI दोनों के लिए एक ही quality gate बनाता है: format, lint और tests।
Deno.serve API example
// app.ts
export type Item = {
id: string;
title: string;
done: boolean;
};
export interface ItemStore {
list(): Promise<Item[]>;
save(items: Item[]): Promise<void>;
}
export class FileItemStore implements ItemStore {
constructor(private readonly path = "./data/items.json") {}
async list(): Promise<Item[]> {
try {
const text = await Deno.readTextFile(this.path);
return JSON.parse(text) as Item[];
} catch (error) {
if (error instanceof Deno.errors.NotFound) {
return [];
}
throw error;
}
}
async save(items: Item[]): Promise<void> {
await Deno.writeTextFile(this.path, JSON.stringify(items, null, 2));
}
}
export function createHandler(store: ItemStore): (request: Request) => Promise<Response> {
return async (request: Request): Promise<Response> => {
const url = new URL(request.url);
if (url.pathname === "/health") {
return Response.json({ ok: true });
}
if (url.pathname === "/api/items" && request.method === "GET") {
return Response.json(await store.list());
}
if (url.pathname === "/api/items" && request.method === "POST") {
const body = await request.json().catch(() => null) as { title?: unknown } | null;
if (!body || typeof body.title !== "string" || body.title.trim() === "") {
return Response.json({ error: "title is required" }, { status: 400 });
}
const items = await store.list();
const item: Item = {
id: crypto.randomUUID(),
title: body.title.trim(),
done: false
};
await store.save([...items, item]);
return Response.json(item, { status: 201 });
}
return new Response("Not Found", { status: 404 });
};
}
// server.ts
import { createHandler, FileItemStore } from "./app.ts";
Deno.serve(
{ hostname: "127.0.0.1", port: 8000 },
createHandler(new FileItemStore())
);
mkdir -p data
printf "[]\n" > data/items.json
deno task dev
curl http://127.0.0.1:8000/health
curl -X POST http://127.0.0.1:8000/api/items \
-H "content-type: application/json" \
-d '{"title":"Deno article draft"}'
curl http://127.0.0.1:8000/api/items
बिना extra permissions के test
// app_test.ts
import { assertEquals } from "@std/assert";
import { createHandler, type Item, type ItemStore } from "./app.ts";
class MemoryStore implements ItemStore {
private items: Item[] = [];
async list(): Promise<Item[]> {
return [...this.items];
}
async save(items: Item[]): Promise<void> {
this.items = [...items];
}
}
Deno.test("GET /health returns ok", async () => {
const handler = createHandler(new MemoryStore());
const response = await handler(new Request("http://localhost/health"));
assertEquals(response.status, 200);
assertEquals(await response.json(), { ok: true });
});
Deno.test("POST /api/items creates an item", async () => {
const handler = createHandler(new MemoryStore());
const response = await handler(
new Request("http://localhost/api/items", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ title: "Write article" })
})
);
const created = await response.json() as Item;
assertEquals(response.status, 201);
assertEquals(created.title, "Write article");
assertEquals(created.done, false);
});
Deno.test("POST /api/items rejects an empty title", async () => {
const handler = createHandler(new MemoryStore());
const response = await handler(
new Request("http://localhost/api/items", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ title: "" })
})
);
assertEquals(response.status, 400);
});
3+ practical use cases
पहला use case internal API prototype है। Admin helper, webhook receiver या JSON demo के लिए Deno.serve काफी हो सकता है।
दूसरा use case repository automation है। Content check, config validation और API snapshot जैसे scripts deno task में साफ रहते हैं।
तीसरा use case team onboarding है। Deno permission errors से नए developers को समझ आता है कि script को network, read या write access क्यों चाहिए।
चौथा use case छोटा HTTP service है जिसे आगे edge/deploy environment में ले जाना हो। Web standard Request और Response code को हल्का रखते हैं।
Common pitfalls
Generated task में -A न छोड़ें। यह सारे permissions खोल देता है।
Express, Jest, Prettier और ESLint तुरंत न जोड़ें। पहले Deno के built-in fmt, lint और test आजमाएं।
data/items.json बनाना न भूलें। File example को directory और file चाहिए।
हर unit test को real file या socket से न जोड़ें। Memory store तेज और permission-free tests देता है।
पुराने examples copy करने से पहले official Deno docs देखें, क्योंकि recommended patterns बदल सकते हैं।
CTA और verification
अगर यह workflow बार-बार इस्तेमाल होगा, तो commands और permissions CLAUDE.md में लिखें। शुरुआत free cheatsheet से करें, reusable prompts के लिए products and templates देखें, और team adoption के लिए training and consultation उपयोग करें।
Hands-on check: data/items.json बनाएं, deno task dev चलाएं, curl से item POST करें, फिर deno task check चलाएं। Review में पहले -A, बहुत बड़े paths और unnecessary test permissions हटाएं।
मुफ़्त PDF: Claude Code cheatsheet
Email डालें और commands, review habits तथा safe workflow वाली एक-page PDF पाएँ.
हम आपका data सुरक्षित रखते हैं और spam नहीं भेजते.
लेखक के बारे में
Masa
Claude Code workflow और team adoption पर काम करने वाला engineer.
संबंधित लेख
Claude Code Obsidian to CLAUDE.md workflow: context बार-बार न समझाएं
Obsidian notes को CLAUDE.md operating notes में बदलकर Claude Code sessions को resume करना आसान बनाएं.
Claude Code Revenue CTA Routing: article से PDF, Gumroad और consultation तक
Reader intent के आधार पर free PDF, Gumroad products और consultation तक CTA route करने वाला workflow.
Claude Code टीम हैंडऑफ नियम: review proof, permissions, rollback और revenue path
Claude Code टीम काम के लिए evidence, permission rules, rollback, free PDF, Gumroad और consultation path वाला handoff.