>_cat deno.md|Web & App Servers
Index

Deno Cheatsheet

SPEC: MDX·/deno·HTTP reverse proxies, application runtimes, and log analysis.

Deno is a modern, secure-by-default runtime for JavaScript, TypeScript, and WebAssembly, built on V8 and Rust. It features explicit security permissions, first-class TypeScript support, Web Standards compatibility, and built-in developer tools.

Installation

Linux / macOS

curl -fsSL https://deno.land/install.sh | sh
source ~/.bashrc   # or source ~/.zshrc

Windows (PowerShell)

powershell -c "irm https://deno.land/install.ps1 | iex"

Via Package Managers

# Homebrew (macOS / Linux)
brew install deno
 
# Arch Linux
sudo pacman -S deno

Upgrade Deno

deno upgrade

Running Scripts

Deno executes both local files and remote HTTP URLs directly, with native support for TypeScript.

deno run main.ts                   # Run local file
deno run https://deno.land/std/examples/welcome.ts # Run remote URL
deno run --watch main.ts           # Automatically restart on file modifications

Security Flags (Explicit Permissions)

By default, scripts run in a restricted sandbox without access to files, network, or environment variables.

# Common permission flags
deno run --allow-net server.ts     # Allow network requests (inbound/outbound)
deno run --allow-net=api.com app.ts # Allow network strictly to specific domain
deno run --allow-read data.json    # Allow filesystem read
deno run --allow-write /tmp app.ts # Allow filesystem write
deno run --allow-env app.ts        # Allow reading environment variables
deno run --allow-run app.ts        # Allow spawning subprocesses
 
# Grant all permissions (development only)
deno run -A main.ts

Built-in Developer Tools

Deno eliminates external tooling setup by integrating linter, formatter, and test runner into a single executable.

Formatting & Linting

deno fmt                           # Auto-format all code files
deno fmt --check                   # Check formatting without modifying
deno lint                          # Run built-in linter

Testing & Benchmarking

deno test                          # Run all tests (*_test.ts, *.test.js)
deno test --watch                  # Run tests on file change
deno bench                         # Run performance benchmarks

Script Tasks (deno task)

Defined in deno.json:

{
  "tasks": {
    "start": "deno run --allow-net main.ts",
    "dev": "deno run --watch --allow-net main.ts"
  }
}
deno task start
deno task dev

Compiling Standalone Binaries

Compile an entire TypeScript/JavaScript program into a self-contained executable binary that runs without Deno installed:

deno compile --allow-net main.ts
./main
 
# Cross-compile for other operating systems
deno compile --target x86_64-pc-windows-msvc main.ts

Package Management & Imports

Deno supports npm packages natively via the npm: prefix, as well as modern ESM imports and JSR (JavaScript Registry).

// Import directly in code without package.json
import express from "npm:express@4";
import { format } from "jsr:@std/datetime";
# Add dependency to deno.json
deno add npm:chalk
deno add jsr:@std/http
deno install                       # Cache/install all project dependencies

Quick Reference

CommandDescription
deno run -A script.tsRun script with all permissions
deno run --watch script.tsRun with watch reload
deno task <name>Execute task from deno.json
deno fmtBuilt-in code formatter
deno lintBuilt-in linter
deno testBuilt-in unit test runner
deno compile main.tsProduce standalone executable