Modern TypeScript runtime with Deno 2 for Google Antigravity IDE
# Deno 2 Development Guide for Google Antigravity
Master Deno 2 for secure, modern TypeScript development with Google Antigravity IDE. This comprehensive guide covers npm compatibility, workspace management, the permissions system, native HTTP servers, and deployment patterns that leverage Deno 2 enhanced features.
## Configuration
Configure your Antigravity environment for Deno 2:
```typescript
// .antigravity/deno.ts
export const denoConfig = {
version: "2.x",
features: {
npmCompat: true,
workspaces: true,
permissions: "strict"
},
deployment: "deno-deploy"
};
```
## Deno Configuration
Set up your deno.json:
```json
{
"tasks": {
"dev": "deno run --watch --allow-net --allow-read main.ts",
"start": "deno run --allow-net --allow-read main.ts",
"test": "deno test --allow-all",
"lint": "deno lint",
"fmt": "deno fmt"
},
"imports": {
"@std/": "jsr:@std/",
"hono": "npm:hono@4",
"zod": "npm:zod@3"
},
"compilerOptions": {
"strict": true,
"lib": ["deno.window"]
},
"workspace": ["./packages/*"]
}
```
## HTTP Server with Hono
Create web applications using Hono:
```typescript
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger } from "hono/logger";
import { z } from "zod";
const app = new Hono();
app.use("*", logger());
app.use("/api/*", cors());
const userSchema = z.object({
name: z.string().min(1),
email: z.string().email()
});
app.get("/", (c) => {
return c.json({ message: "Hello from Deno 2!" });
});
app.get("/api/users", async (c) => {
const kv = await Deno.openKv();
const users: User[] = [];
for await (const entry of kv.list({ prefix: ["users"] })) {
users.push(entry.value as User);
}
return c.json(users);
});
app.post("/api/users", async (c) => {
const body = await c.req.json();
const validated = userSchema.parse(body);
const kv = await Deno.openKv();
const id = crypto.randomUUID();
const user = { id, ...validated, createdAt: new Date().toISOString() };
await kv.set(["users", id], user);
return c.json(user, 201);
});
Deno.serve({ port: 3000 }, app.fetch);
```
## Deno KV Database
Use the built-in key-value store:
```typescript
const kv = await Deno.openKv();
async function createUser(user: Omit<User, "id">) {
const id = crypto.randomUUID();
const newUser = { id, ...user };
const result = await kv.atomic()
.check({ key: ["users_by_email", user.email], versionstamp: null })
.set(["users", id], newUser)
.set(["users_by_email", user.email], id)
.commit();
if (!result.ok) {
throw new Error("Email already exists");
}
return newUser;
}
async function getUser(id: string) {
const result = await kv.get<User>(["users", id]);
return result.value;
}
async function getUserByEmail(email: string) {
const idResult = await kv.get<string>(["users_by_email", email]);
if (!idResult.value) return null;
return getUser(idResult.value);
}
```
## Permission Patterns
Handle permissions securely:
```typescript
async function requestPermissions() {
const netStatus = await Deno.permissions.request({ name: "net" });
const readStatus = await Deno.permissions.request({
name: "read",
path: "./data"
});
return {
net: netStatus.state === "granted",
read: readStatus.state === "granted"
};
}
async function checkPermission(name: "net" | "read" | "write", path?: string) {
const desc: Deno.PermissionDescriptor = path
? { name, path } as Deno.PermissionDescriptor
: { name };
const status = await Deno.permissions.query(desc);
return status.state === "granted";
}
```
## Testing in Deno
Write comprehensive tests:
```typescript
import { assertEquals, assertRejects } from "@std/assert";
import { createUser, getUser, deleteUser } from "./user.ts";
Deno.test("User CRUD operations", async (t) => {
const testUser = { name: "Test User", email: "test@example.com" };
let userId: string;
await t.step("creates a new user", async () => {
const user = await createUser(testUser);
userId = user.id;
assertEquals(user.name, testUser.name);
assertEquals(user.email, testUser.email);
});
await t.step("retrieves user by id", async () => {
const user = await getUser(userId);
assertEquals(user?.name, testUser.name);
});
await t.step("deletes user", async () => {
await deleteUser(userId);
const user = await getUser(userId);
assertEquals(user, null);
});
});
```
## Best Practices
Follow these guidelines for Deno 2:
1. **Use JSR imports** - Prefer jsr: over npm: when available
2. **Leverage KV** - Built-in persistence for serverless
3. **Strict permissions** - Request only what you need
4. **Use workspaces** - Organize monorepos effectively
5. **Deploy to Deno Deploy** - Zero-config edge deployment
6. **Type everything** - Full TypeScript support built-in
Google Antigravity IDE provides intelligent Deno API suggestions and permission management for secure development.This Deno prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their deno implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For Deno projects, consider mentioning your framework version, coding style, and any specific libraries you're using.