liminfo

Deno Runtime Reference

Free reference guide: Deno Runtime Reference

21 results

About Deno Runtime Reference

The Deno Runtime Reference is a practical, searchable cheat sheet covering the essential Deno APIs and CLI commands used in modern TypeScript server-side development. It covers 4 categories: Runtime (Deno.serve, Deno.readFile, Deno.readTextFile, Deno.writeFile, Deno.writeTextFile, Deno.env, Deno.Command, Deno.cwd), CLI (deno run, deno fmt, deno lint, deno test, deno compile, deno bench), Permissions (--allow-net, --allow-read, --allow-write, --allow-env, --allow-run), and Config (deno.json, Import Maps). Every entry includes a real code example.

Deno is a modern JavaScript and TypeScript runtime built on V8, Rust, and Tokio. Unlike Node.js, Deno is secure by default — no script has access to the file system, network, or environment variables unless you explicitly grant permission with flags like --allow-net or --allow-read. This reference is aimed at backend developers, full-stack TypeScript engineers, and developers migrating from Node.js. The Runtime section covers the complete Deno namespace API for building HTTP servers (Deno.serve), reading and writing files as both raw bytes (Deno.readFile/writeFile) and text (Deno.readTextFile/writeTextFile), accessing environment variables (Deno.env.get()), and running child processes (Deno.Command).

The Permissions section is unique to Deno and critical for security. Rather than having broad access by default, Deno scripts must declare exactly which resources they need. Permissions can be scoped narrowly: --allow-net=example.com:443 permits only HTTPS connections to a specific domain, --allow-read=./data permits reads only from a specific directory, --allow-env=PORT,HOST permits only specific environment variables. The Config section covers deno.json — Deno's project configuration file where you define tasks (like npm scripts), import maps for module aliasing, TypeScript compiler options, and linter/formatter settings. Import Maps let you replace long URLs with short aliases like "oak" → "jsr:@oak/oak@^14".

Key Features

  • Covers 4 categories: Runtime API, CLI commands, Permissions, and Config with real code examples
  • HTTP server: Deno.serve() with port and request handler — no framework required
  • File I/O: Deno.readFile/writeFile (bytes) and Deno.readTextFile/writeTextFile (text) APIs
  • Child process execution with Deno.Command — replaces deprecated Deno.run()
  • Environment variables: Deno.env.get() for runtime access, --allow-env permission scoping
  • CLI tools: deno fmt (formatting), deno lint (linting), deno test, deno compile to single binary, deno bench
  • Fine-grained permission flags: --allow-net, --allow-read, --allow-write, --allow-env, --allow-run with scope examples
  • deno.json project config: task runner, import maps for JSR/npm module aliasing, TypeScript settings

Frequently Asked Questions

How is Deno different from Node.js?

Deno and Node.js are both JavaScript runtimes built on V8, but differ in several key ways. Deno is secure by default — it denies all file, network, and environment access unless you grant explicit permissions with flags. Deno has built-in TypeScript support with no configuration needed. Deno uses ES modules (import/export) natively and does not have a package.json or node_modules — dependencies are imported directly from URLs or JSR. Deno includes built-in tools: formatter (deno fmt), linter (deno lint), test runner (deno test), and bundler (deno compile). Node.js has a larger ecosystem, but Deno has compatibility with many npm packages via npm: specifiers.

How do Deno permissions work?

By default, a Deno script has no access to the file system, network, environment variables, or subprocesses. You must explicitly grant permissions using CLI flags when running the script. Common flags: --allow-net (all network), --allow-net=example.com (specific domain), --allow-read (all files), --allow-read=./data (specific path), --allow-write=./output (specific path), --allow-env (all env vars), --allow-env=PORT (specific variable), --allow-run=git (specific subprocess). Use --allow-all (-A) for development convenience, but never in production. You can also prompt for permissions at runtime using Deno.permissions.request().

How do I create an HTTP server with Deno?

The simplest way is Deno.serve(), which became stable in Deno 1.35. Pass a port and a handler function that receives a Request and returns a Response: Deno.serve({ port: 8000 }, (req) => new Response("Hello!")). For a full web framework, Oak is popular: import { Application } from "jsr:@oak/oak". Run with: deno run --allow-net server.ts. Deno.serve() uses the Web-standard Request and Response APIs, making code portable between Deno and other runtimes like Cloudflare Workers.

How do I run, format, lint, and test Deno code?

deno run --allow-net server.ts runs a script with network permission. deno fmt formats all TypeScript/JavaScript files according to Deno's style (similar to Prettier). deno fmt --check verifies formatting without modifying files (useful in CI). deno lint checks for common code quality issues. deno lint --fix auto-fixes fixable issues. deno test runs all files matching *_test.ts or *.test.ts patterns using Deno.test(). deno bench runs benchmark functions defined with Deno.bench(). deno compile --allow-net server.ts compiles the script to a standalone executable binary.

What is deno.json and what can I configure in it?

deno.json (or deno.jsonc) is Deno's project configuration file. It supports: tasks (like npm scripts) defined under the "tasks" key, runnable with deno task name; imports (Import Map) for aliasing modules — "std/": "https://deno.land/std/"; compilerOptions for TypeScript settings; lint rules and formatter options. You can also configure which files to include/exclude, test patterns, and unstable API flags. Run deno task dev to run the "dev" task defined in your deno.json.

How do Import Maps work in Deno?

Import Maps allow you to map short module specifiers to full URLs. Instead of writing import { Application } from "https://deno.land/x/oak/mod.ts" in every file, you define "oak": "jsr:@oak/oak@^14" in the "imports" field of deno.json or a separate importmap.json. Then you can write import { Application } from "oak" anywhere in your project. Import Maps also support path aliases like "@/": "./src/" for project-relative imports. This is Deno's equivalent of the paths configuration in TypeScript or the # imports field in package.json.

How does Deno.Command work for running subprocesses?

Deno.Command is the current API for spawning child processes (it replaced the deprecated Deno.run()). Create a command: const cmd = new Deno.Command("ls", { args: ["-la"] }). Call cmd.output() to run and collect stdout/stderr as Uint8Arrays, or cmd.spawn() for a long-running process with streaming I/O. You need --allow-run permission (or --allow-run=ls to scope it to a specific executable). Use new TextDecoder().decode(output.stdout) to convert the output to a string.

How do I compile a Deno script to a standalone executable?

deno compile --allow-net server.ts creates a self-contained executable binary that includes the Deno runtime, your script, and all its dependencies. The output file can be run on any machine with the same OS/architecture without installing Deno separately. Include all required permission flags in the compile command — they become baked-in defaults for the binary. Use --output my-server to specify the output filename. For cross-compilation (building for a different OS), use the --target flag with a target triple like x86_64-unknown-linux-gnu.