Deno Cheatsheet
Deno is a secure JavaScript and TypeScript runtime built by Node.js creator Ryan Dahl. It features built-in TypeScript compilation, formatting, linting, testing, a secure-by-default permission system, and native support for Web APIs, JSR, and npm packages.
Quick Start
``bash
# Run a script
deno run main.ts
# Run with network access deno run --allow-net main.ts
# Watch mode — auto-restart on changes deno run --watch main.ts
# Format code deno fmt
# Run tests deno test
# Start REPL deno repl
# Evaluate inline code
deno eval 'console.log("hello deno")'
`
Install & Setup
`bash
deno --version # Show version info
deno upgrade # Upgrade to latest
deno upgrade --version 2.0.0 # Upgrade/downgrade to specific version
deno info # Show cache and module resolution info
`
Basic Usage
`bash
deno run main.ts # Run a file
deno run --watch main.ts # Watch mode (auto-restart on file changes)
deno eval 'console.log("hi")' # Run inline code
deno repl # Start interactive REPL
`
Script Management
`bash
deno compile --allow-read main.ts # Compile to standalone binary
deno compile --target x86_64-unknown-linux-gnu main.ts # Cross-compile
deno compile --output dist/cli main.ts # Custom output name
deno install -g --allow-net --allow-read https://deno.land/std/http/file_server.ts # Install global script
deno uninstall file_server # Uninstall global script
deno task dev # Run task from deno.json
deno task --watch test # Task watch mode
`
Permissions
`bash
deno run --allow-read main.ts # Allow file system read
deno run --allow-write main.ts # Allow file system write
deno run --allow-net main.ts # Allow network access
deno run --allow-env main.ts # Allow env variable access
deno run --allow-all main.ts # Grant all permissions
deno run --allow-read=/data --allow-write=/tmp main.ts # Scope to paths
deno run --allow-net --deny-net=api.example.com main.ts # Deny specific hosts
`
Package Management
`bash
deno add @std/assert # Add JSR dependency
deno add npm:express # Add npm dependency
deno remove @std/assert # Remove a dependency
deno publish # Publish module to JSR
deno cache main.ts # Cache remote module dependencies
`
Testing & Lint
`bash
deno test # Run all tests
deno test --watch # Run tests in watch mode
deno test --coverage # Run tests with coverage collection
deno bench # Run benchmarks
deno lint # Lint code for style & errors
deno fmt # Format code (built-in formatter)
deno check main.ts # Type-check without executing
`
Advanced
`bash
deno doc mod.ts # Generate documentation
deno doc --json mod.ts # Output docs in JSON format
deno jupyter --install # Start Jupyter kernel (experimental)
deno serve main.ts # Start HTTP server (Fetch API)
deno run --v8-flags=--max-old-space-size=2048 main.ts # Set V8 memory
deno run --inspect-brk main.ts # Debug (paused at first statement)
`
FAQ
### How do I configure Deno?
Create a deno.json or deno.jsonc in your project root. It supports tasks, imports (import map), compiler options, lint/fmt settings, and publish configuration. Example:
`json
{
"tasks": {
"dev": "deno run --watch --allow-net main.ts",
"test": "deno test --coverage"
},
"imports": {
"express": "npm:express@^5.0.0"
}
}
`
### How do I use Web APIs in Deno?
Deno implements browser-compatible Web APIs: fetch, Request, Response, WebSocket, Console, setTimeout, URL, Blob, File, FormData, TextEncoder, ReadableStream, and more. No polyfills needed — they Just Work.
`typescript
// Fetch example (needs --allow-net)
const res = await fetch('https://api.example.com');
const data = await res.json();
`
### How do I debug Deno scripts?
Use --inspect or --inspect-brk to start the V8 inspector, then connect Chrome DevTools or VS Code debugger:
`bash
deno run --inspect-brk main.ts
# Open chrome://inspect in Chrome
``
Install & Setup(4)
| Command | Level | ||
|---|---|---|---|
deno --versionShow Deno, TypeScript, and V8 engine versions | Basic | deno --version | |
deno upgradeUpgrade Deno to the latest version | Basic | deno upgrade | |
deno upgrade --version 2.0.0Upgrade or downgrade to a specific version | Intermediate | deno upgrade --version 2.0.0 | |
deno infoShow cache and module resolution info | Basic | deno info |
Basic Usage(4)
| Command | Level | ||
|---|---|---|---|
deno runRun a TypeScript or JavaScript file | Basic | deno run main.ts | |
deno run --watchWatch mode — auto-restart on file changes | Intermediate | deno run --watch main.ts | |
deno evalRun inline code snippet | Basic | deno eval 'console.log("hello")' | |
deno replStart an interactive REPL session | Basic | deno repl |
Script Management(7)
| Command | Level | ||
|---|---|---|---|
deno compileCompile script into a standalone executable | Intermediate | deno compile --allow-read main.ts | |
deno compile --target x86_64-unknown-linux-gnuCross-compile for a specific target platform | Expert | deno compile --target x86_64-unknown-linux-gnu main.ts | |
deno compile --output dist/cliSpecify output binary name | Intermediate | deno compile --output dist/cli main.ts | |
deno installInstall a remote script as a global command | Intermediate | deno install -g --allow-net --allow-read https://deno.land/std/http/file_server.ts | |
deno uninstallUninstall a previously installed global command | Basic | deno uninstall file_server | |
deno taskRun a task defined in deno.json | Basic | deno task dev | |
deno task --watchRun task in watch mode (re-run on changes) | Intermediate | deno task --watch test |
Permissions(7)
| Command | Level | ||
|---|---|---|---|
deno run --allow-readAllow file system read access | Basic | deno run --allow-read main.ts | |
deno run --allow-writeAllow file system write access | Basic | deno run --allow-write main.ts | |
deno run --allow-netAllow network access | Basic | deno run --allow-net main.ts | |
deno run --allow-allGrant all permissions (not recommended for production) | Basic | deno run --allow-all main.ts | |
deno run --deny-net=api.example.comDeny access to specific network addresses | Expert | deno run --allow-net --deny-net=api.example.com main.ts | |
deno run --allow-envAllow environment variable access | Basic | deno run --allow-env main.ts | |
deno run --allow-read=/data --allow-write=/tmpScope file permissions to specific paths | Intermediate | deno run --allow-read=/data --allow-write=/tmp main.ts |
Package Management(5)
| Command | Level | ||
|---|---|---|---|
deno addAdd a JSR or npm package to the project | Basic | deno add @std/assert | |
deno removeRemove a dependency from the project | Basic | deno remove @std/assert | |
deno add npm:expressAdd an npm-compatible package | Basic | deno add npm:express | |
deno publishPublish a module to JSR | Intermediate | deno publish | |
deno cacheCache remote module dependencies | Intermediate | deno cache main.ts |
Testing & Lint(7)
| Command | Level | ||
|---|---|---|---|
deno testRun tests | Basic | deno test | |
deno test --watchRun tests in watch mode | Intermediate | deno test --watch | |
deno test --coverageRun tests with coverage collection | Intermediate | deno test --coverage | |
deno benchRun benchmarks | Intermediate | deno bench | |
deno lintLint code for style and potential errors | Basic | deno lint | |
deno fmtFormat code with built-in formatter | Basic | deno fmt | |
deno checkType-check code without executing | Intermediate | deno check main.ts |
Advanced(6)
| Command | Level | ||
|---|---|---|---|
deno docGenerate documentation for a module | Intermediate | deno doc mod.ts | |
deno doc --jsonOutput docs in JSON format | Intermediate | deno doc --json mod.ts | |
deno jupyterStart Jupyter Notebook kernel (experimental) | Expert | deno jupyter --install | |
deno serveStart an HTTP server using built-in Fetch API | Expert | deno serve main.ts | |
deno run --v8-flags=--max-old-space-size=2048Set V8 engine memory limit | Expert | deno run --v8-flags=--max-old-space-size=2048 main.ts | |
deno run --inspect-brkEnable debugger, paused at first statement | Expert | deno run --inspect-brk main.ts |