Deno Cheat Sheet
Quick reference for Deno — runtime commands, permissions, HTTP server, file system, testing, and TypeScript-first patterns. All essential Deno 2.x patterns in one page.
CLI Commands
| deno run main.ts | Run a TypeScript/JavaScript file |
| deno run --allow-net main.ts | Run with network permission |
| deno run --allow-all main.ts | Run with all permissions (dev only) |
| deno task dev | Run task from deno.json |
| deno fmt | Format code (built-in Prettier alternative) |
| deno lint | Lint code (built-in ESLint alternative) |
| deno test | Run all tests |
| deno bench | Run benchmarks |
| deno compile main.ts | Compile to standalone executable |
| deno check main.ts | Type-check without running |
| deno info main.ts | Show dependency tree |
| deno doc mod.ts | Generate documentation |
Permissions
| --allow-read | File system read access |
| --allow-write | File system write access |
| --allow-net | Network access |
| --allow-env | Environment variable access |
| --allow-run | Subprocess execution |
| --allow-ffi | Foreign function interface |
| --allow-sys | System info access |
| --allow-read=/tmp | Scoped read to /tmp only |
| --allow-net=api.example.com | Network access to specific host |
| --deny-net | Explicitly deny network (overrides allow) |
HTTP Server
| Deno.serve(req => new Response("Hello")) | Minimal HTTP server |
| Deno.serve({ port: 3000 }, handler) | Server on custom port |
| new Response(body, { status: 200 }) | Create response with status |
| new Response(JSON.stringify(data), { headers: { "content-type": "application/json" } }) | JSON response |
| new URL(req.url).pathname | Get request path |
| await req.json() | Parse JSON request body |
| req.method === "POST" | Check HTTP method |
| new Response(null, { status: 301, headers: { location: "/new" } }) | Redirect response |
File System
| await Deno.readTextFile("file.txt") | Read text file |
| await Deno.writeTextFile("file.txt", "data") | Write text file |
| await Deno.readFile("image.png") | Read binary file → Uint8Array |
| for await (const entry of Deno.readDir(".")) | Iterate directory entries |
| await Deno.stat("file.txt") | Get file info (size, mtime) |
| await Deno.mkdir("dir", { recursive: true }) | Create directory |
| await Deno.remove("file.txt") | Delete file |
| await Deno.rename("old.txt", "new.txt") | Rename / move file |
Testing
| Deno.test("name", () => { ... }) | Basic test |
| Deno.test("async", async () => { ... }) | Async test |
| import { assertEquals } from "jsr:@std/assert" | Import assertion |
| assertEquals(actual, expected) | Assert equality |
| assertThrows(() => fn(), Error) | Assert throws error |
| Deno.test({ name: "test", permissions: { net: true } }, fn) | Test with specific permissions |
| deno test --filter "pattern" | Run tests matching pattern |
| deno test --coverage | Run with coverage collection |
Imports & Configuration
| import { serve } from "jsr:@std/http" | Import from JSR registry |
| import oak from "npm:@oak/oak" | Import npm package |
| import { z } from "npm:zod" | Use npm packages directly |
| import map from "./import_map.json" with { type: "json" } | Import JSON with assertion |
| // deno.json: { "imports": { "@std/": "jsr:@std/" } } | Import map in deno.json |
| // deno.json: { "tasks": { "dev": "deno run --watch main.ts" } } | Define tasks |
| Deno.env.get("API_KEY") | Read environment variable |
| Deno.env.set("KEY", "value") | Set environment variable |
Step-by-Step Guide
Read Guide →