Build modern server applications with Deno, Oak framework, and native TypeScript in Google Antigravity
# Deno Runtime Development for Google Antigravity
Deno provides a secure runtime with native TypeScript support. This guide covers patterns optimized for Google Antigravity IDE and Gemini 3.
## Oak Server Setup
```typescript
// main.ts
import { Application, Router, Context } from 'https://deno.land/x/oak@v12.6.1/mod.ts';
import { oakCors } from 'https://deno.land/x/cors@v1.2.2/mod.ts';
const router = new Router();
// Middleware for logging
const logger = async (ctx: Context, next: () => Promise<unknown>) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
console.log(`${ctx.request.method} ${ctx.request.url.pathname} - ${ms}ms`);
};
// Routes
router.get('/api/health', (ctx) => {
ctx.response.body = { status: 'ok', timestamp: new Date().toISOString() };
});
router.get('/api/users', async (ctx) => {
const users = await getUsers();
ctx.response.body = users;
});
router.post('/api/users', async (ctx) => {
const body = await ctx.request.body().value;
const user = await createUser(body);
ctx.response.status = 201;
ctx.response.body = user;
});
router.get('/api/users/:id', async (ctx) => {
const user = await getUser(ctx.params.id);
if (!user) {
ctx.response.status = 404;
ctx.response.body = { error: 'User not found' };
return;
}
ctx.response.body = user;
});
const app = new Application();
app.use(oakCors());
app.use(logger);
app.use(router.routes());
app.use(router.allowedMethods());
console.log('Server running on http://localhost:8000');
await app.listen({ port: 8000 });
```
## Database with Deno KV
```typescript
// db/kv.ts
const kv = await Deno.openKv();
interface User {
id: string;
email: string;
name: string;
createdAt: Date;
}
export async function createUser(data: Omit<User, 'id' | 'createdAt'>): Promise<User> {
const id = crypto.randomUUID();
const user: User = { ...data, id, createdAt: new Date() };
await kv.atomic()
.check({ key: ['users', id], versionstamp: null })
.check({ key: ['users_by_email', data.email], versionstamp: null })
.set(['users', id], user)
.set(['users_by_email', data.email], id)
.commit();
return user;
}
export async function getUser(id: string): Promise<User | null> {
const result = await kv.get<User>(['users', id]);
return result.value;
}
export async function getUsers(): Promise<User[]> {
const users: User[] = [];
for await (const entry of kv.list<User>({ prefix: ['users'] })) {
users.push(entry.value);
}
return users;
}
export async function getUserByEmail(email: string): Promise<User | null> {
const idResult = await kv.get<string>(['users_by_email', email]);
if (!idResult.value) return null;
return getUser(idResult.value);
}
export async function deleteUser(id: string): Promise<boolean> {
const user = await getUser(id);
if (!user) return false;
await kv.atomic()
.delete(['users', id])
.delete(['users_by_email', user.email])
.commit();
return true;
}
```
## Fresh Web Framework
```typescript
// routes/index.tsx
import { Head } from '$fresh/runtime.ts';
import Counter from '../islands/Counter.tsx';
export default function Home() {
return (
<>
<Head>
<title>Fresh App</title>
</Head>
<div class="p-4 mx-auto max-w-screen-md">
<h1 class="text-4xl font-bold">Welcome to Fresh</h1>
<Counter start={3} />
</div>
</>
);
}
// islands/Counter.tsx
import { useSignal } from '@preact/signals';
interface CounterProps {
start: number;
}
export default function Counter(props: CounterProps) {
const count = useSignal(props.start);
return (
<div class="flex gap-4 items-center">
<button onClick={() => count.value--} class="px-4 py-2 bg-gray-200 rounded">-</button>
<p class="text-2xl">{count}</p>
<button onClick={() => count.value++} class="px-4 py-2 bg-blue-500 text-white rounded">+</button>
</div>
);
}
```
## Testing
```typescript
// tests/user_test.ts
import { assertEquals, assertExists } from 'https://deno.land/std@0.208.0/assert/mod.ts';
import { createUser, getUser, deleteUser } from '../db/kv.ts';
Deno.test('User CRUD operations', async (t) => {
let userId: string;
await t.step('create user', async () => {
const user = await createUser({ email: 'test@example.com', name: 'Test User' });
assertExists(user.id);
assertEquals(user.email, 'test@example.com');
userId = user.id;
});
await t.step('get user', async () => {
const user = await getUser(userId);
assertExists(user);
assertEquals(user.name, 'Test User');
});
await t.step('delete user', async () => {
const deleted = await deleteUser(userId);
assertEquals(deleted, true);
const user = await getUser(userId);
assertEquals(user, null);
});
});
```
## Best Practices
1. **Permissions**: Run with minimal permissions
2. **Import Maps**: Use import_map.json for dependencies
3. **Deno KV**: Built-in key-value database
4. **TypeScript**: Native support, no config needed
5. **Testing**: Built-in test runner
6. **Deploy**: Deno Deploy for edge functions
Google Antigravity's Gemini 3 understands Deno patterns and generates secure server code.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.