Setup and context
Deno 2 is the next-generation JavaScript and TypeScript runtime designed by Ryan Dahl, the original creator of Node.js. It ships with security-first permission management, zero-config TypeScript support, and full npm compatibility — everything a modern developer needs right out of the box.
When paired with Antigravity, you can delegate Deno 2's permission configuration and module design to AI agents while building secure, high-performance applications. This guide walks you through environment setup, full-stack development with the Fresh framework, and deploying to Deno Deploy.
Why Deno 2 and Antigravity Work Well Together
There are several reasons Deno 2 is a compelling choice for developers, and each aligns naturally with Antigravity's capabilities.
First, the permission system. Every system resource — file access, network calls, environment variables — requires explicit authorization. Antigravity's agents analyze generated code to determine exactly which permissions are needed and reflect them in deno.json, avoiding overly permissive configurations.
Second, the TypeScript-first design. There's no need for tsconfig.json tweaks or transpilers like ts-node. You can run .ts files directly. This pairs perfectly with the type-safe code Antigravity generates.
Third, npm compatibility mode lets you use existing npm packages with the npm: prefix. You maintain a clean project structure without node_modules while still accessing popular libraries like Express and Prisma.
Starting a Deno 2 Project with Antigravity
Open Antigravity's terminal and give the agent a prompt like this:
Create a REST API server using Deno 2.
Use the Oak framework and implement CRUD operations for users.
Include permission settings in deno.json.
Antigravity generates a project structure like the following:
my-deno-api/
├── deno.json
├── main.ts
├── routes/
│ └── users.ts
├── middleware/
│ └── logger.ts
├── models/
│ └── user.ts
└── tests/
└── users_test.ts
The deno.json file includes the necessary permissions and task definitions:
{
"tasks": {
"dev": "deno run --watch --allow-net --allow-read --allow-env main.ts",
"start": "deno run --allow-net --allow-read --allow-env main.ts",
"test": "deno test --allow-net --allow-read --allow-env"
},
"imports": {
"@oak/oak": "jsr:@oak/oak@^17",
"@std/assert": "jsr:@std/assert@^1"
}
}Notice how only the minimum required permissions — --allow-net, --allow-read, --allow-env — are granted. Antigravity analyzes your code and avoids the catch-all --allow-all flag, keeping your application secure by default.
Building a REST API with Oak
Oak is a lightweight HTTP framework for Deno that provides an Express-like API. When you ask Antigravity to build a user management API with Oak, it generates routing code like this:
// routes/users.ts
import { Router } from "@oak/oak";
interface User {
id: string;
name: string;
email: string;
}
const users: Map<string, User> = new Map();
const router = new Router();
router
.get("/api/users", (ctx) => {
ctx.response.body = [...users.values()];
})
.get("/api/users/:id", (ctx) => {
const user = users.get(ctx.params.id);
if (!user) {
ctx.response.status = 404;
ctx.response.body = { error: "User not found" };
return;
}
ctx.response.body = user;
})
.post("/api/users", async (ctx) => {
const body = await ctx.request.body.json();
const user: User = {
id: crypto.randomUUID(),
name: body.name,
email: body.email,
};
users.set(user.id, user);
ctx.response.status = 201;
ctx.response.body = user;
});
export default router;Antigravity's code completion recognizes Deno's standard library (@std/) and JSR registry modules, so runtime APIs like crypto.randomUUID() are suggested accurately.
Full-Stack Development with Fresh
For full-stack Deno 2 development, the Fresh framework is an excellent choice. Fresh uses an islands architecture where only the interactive parts of your page are hydrated on the client side.
Give Antigravity a prompt like this:
Build a blog app with Fresh 2.
Implement a post listing page and a post detail page.
Load content from markdown files.
Fresh uses file-based routing where files in the routes/ directory map directly to URL paths. Antigravity understands this convention and generates files in the correct locations.
blog-app/
├── deno.json
├── main.ts
├── routes/
│ ├── index.tsx # Post listing
│ └── posts/
│ └── [slug].tsx # Post detail
├── islands/
│ └── LikeButton.tsx # Interactive component
├── components/
│ └── PostCard.tsx # Server-side component
└── content/
├── hello-world.md
└── getting-started.md
Only components placed in islands/ are included in the JavaScript bundle, resulting in excellent performance characteristics for your site.
Test-Driven Development with Antigravity
Deno 2 ships with a built-in test runner. When you ask Antigravity to generate tests, it creates test code using Deno.test():
// tests/users_test.ts
import { assertEquals } from "@std/assert";
Deno.test("POST /api/users creates a new user", async () => {
const response = await fetch("http://localhost:8000/api/users", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
name: "Alice Johnson",
email: "alice@example.com",
}),
});
const user = await response.json();
assertEquals(response.status, 201);
assertEquals(user.name, "Alice Johnson");
});Run tests with a single deno test command and generate coverage reports with the --coverage flag. Antigravity's agent analyzes test results and immediately suggests fixes for any failing cases.
Deploying to Deno Deploy
Deno Deploy is the official edge hosting service for Deno, enabling automatic deployments through GitHub integration. Here's how to set it up from Antigravity.
First, install deployctl:
deno install -gArf jsr:@deno/deployctlThen link your GitHub repository to a Deno Deploy project:
deployctl deploy --project=my-deno-api --entrypoint=main.tsAntigravity can also generate GitHub Actions workflow files to set up a CI/CD pipeline with preview deployments on every pull request:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
- run: deno task build
- uses: denoland/deployctl@v1
with:
project: my-deno-api
entrypoint: main.tsWorking with npm Packages
Deno 2's npm: prefix lets you use popular npm packages like Prisma, Zod, and Hono without any additional tooling:
import { z } from "npm:zod@3";
import { Hono } from "npm:hono@4";
const UserSchema = z.object({
name: z.string().min(1),
email: z.string().email(),
});
const app = new Hono();
app.post("/users", async (c) => {
const body = await c.req.json();
const result = UserSchema.safeParse(body);
if (!result.success) {
return c.json({ errors: result.error.issues }, 400);
}
return c.json({ user: result.data }, 201);
});
Deno.serve(app.fetch);Antigravity understands the difference between npm: and jsr: imports and will prefer Deno-native packages from the JSR registry when they're available.
Permission Design Best Practices
To make the most of Deno's permission system, ask Antigravity to analyze your project's permission requirements. It scans the entire codebase and identifies exactly which resources are accessed.
Here are common permission patterns and their use cases:
--allow-net=api.example.com: Restrict network access to specific hosts. Use for external API calls.--allow-read=./content,./config: Limit file reads to specific directories. Use for configuration and content loading.--allow-env=DATABASE_URL,API_KEY: Allow access to specific environment variables only. Use for secrets management.
Reserve --allow-all for debugging only and always apply the principle of least privilege in production. Antigravity automatically generates configurations that follow this principle.
Wrapping Up
Deno 2 combined with Antigravity delivers a development environment that balances security with productivity. Zero-config TypeScript support, granular permission management, and full npm compatibility make it straightforward to build modern web applications at speed.
Antigravity's agents understand the Deno 2 ecosystem — JSR, Fresh, Oak, and Deno Deploy — so you get consistent AI assistance from project initialization through deployment. Give it a try on your next project.