๐Ÿ“‹ Cheat Sheets

Deno Cheat Sheet โ€” Commands, Permissions, and Common Patterns


Click any item to expand the explanation and examples.

๐Ÿš€ Run & Execute

deno run run
deno run main.ts                          # Run TypeScript directly
deno run --allow-net main.ts              # With network permission
deno run --allow-all main.ts              # All permissions
deno run --watch main.ts                  # Watch mode (auto-restart)
deno run https://example.com/script.ts    # Run from URL
deno task (scripts) run
// deno.json
{
  "tasks": {
    "dev": "deno run --watch --allow-net main.ts",
    "start": "deno run --allow-net main.ts",
    "test": "deno test"
  }
}
deno task dev
deno task test

๐Ÿ”’ Permissions

Permission flags security

Deno is secure by default โ€” no file, network, or env access unless you allow it.

--allow-net                    # All network access
--allow-net=api.example.com    # Specific host only
--allow-read                   # All file reads
--allow-read=./data            # Specific directory
--allow-write                  # All file writes
--allow-env                    # Environment variables
--allow-env=API_KEY            # Specific variable
--allow-run                    # Run subprocesses
--allow-all                    # Everything (like Node.js)
-A                             # Shorthand for --allow-all

๐Ÿ“ฆ Dependencies

Imports and deno.json deps
// Import from URL
import { serve } from "https://deno.land/std/http/server.ts";

// Import from npm
import express from "npm:express";
import chalk from "npm:chalk";

// Import map in deno.json
// deno.json: { "imports": { "@std/": "https://deno.land/std/" } }
import { join } from "@std/path";
deno add @std/path             # Add to import map
deno add npm:express           # Add npm package

๐Ÿงช Testing

deno test test
// main_test.ts (Deno finds *_test.ts files automatically)
import { assertEquals } from "@std/assert";

Deno.test("addition", () => {
  assertEquals(1 + 1, 2);
});

Deno.test("async test", async () => {
  const data = await fetchData();
  assertEquals(data.length, 10);
});
deno test                      # Run all tests
deno test --watch              # Watch mode
deno test --filter "addition"  # Run matching tests
deno test --coverage           # With coverage

๐Ÿ› ๏ธ Tools

Built-in toolchain tools
deno fmt                       # Format code (like Prettier)
deno lint                      # Lint code
deno check main.ts             # Type-check without running
deno compile main.ts           # Compile to standalone binary
deno doc main.ts               # Generate documentation
deno bench bench.ts            # Run benchmarks
deno jupyter                   # Start Jupyter kernel

See also: TypeScript cheat sheet | npm cheat sheet