Skip to main content
Deno’s runtime is built on a modular extension system that provides native functionality to JavaScript code. Each extension implements specific web platform APIs or Deno-specific features, bridging the gap between JavaScript and the underlying system.

What are Extensions?

Extensions (located in ext/) are modules that:
  • Implement web platform standards (Fetch, WebSocket, Web Crypto, etc.)
  • Provide system access through Rust operations (“ops”)
  • Include both Rust and JavaScript code
  • Are registered with the JavaScript runtime at initialization

Architecture

Each extension consists of:
  1. Rust code (lib.rs, *.rs) - Implements the low-level operations (ops) that JavaScript can call
  2. JavaScript code (*.js) - Provides the high-level APIs that users interact with
  3. Extension definition - Declares ops, ESM modules, and dependencies
deno_core::extension!(deno_fetch,
  deps = [ deno_webidl, deno_web ],
  ops = [
    op_fetch,
    op_fetch_send,
    // ...
  ],
  esm = [
    "20_headers.js",
    "26_fetch.js",
  ]
);

Core Extensions

Web Platform APIs

Web Extension

Core web APIs including streams, encoding, blobs, and events

Fetch

HTTP client implementation following the Fetch API standard

WebSocket

WebSocket client and server implementation

Web Crypto

Cryptographic operations following the Web Crypto API

Server APIs

HTTP Server

High-performance HTTP/1.1 and HTTP/2 server

Web Storage

localStorage and sessionStorage implementation

BroadcastChannel

Cross-context message broadcasting

Graphics and Compute

WebGPU

GPU access for graphics and compute operations

Extension Dependencies

Extensions can depend on other extensions. Common dependencies include:
  • deno_webidl - WebIDL type conversions
  • deno_web - Core web platform types and utilities
  • deno_fetch - HTTP client functionality

How Extensions Work

Operations (Ops)

Ops are Rust functions exposed to JavaScript:
#[op2]
pub fn op_example(#[string] input: String) -> String {
  format!("Hello, {}!", input)
}
JavaScript can call this through the internal Deno.core.ops object.

Resources

Extensions manage resources (files, sockets, etc.) through resource IDs:
pub struct MyResource {
  data: Vec<u8>,
}

impl Resource for MyResource {
  fn name(&self) -> Cow<'_, str> {
    "myResource".into()
  }
}

// Store in resource table
let rid = state.resource_table.add(MyResource { data });

Building Custom Extensions

To add a new extension:
  1. Create a directory in ext/
  2. Implement Rust ops in lib.rs
  3. Add JavaScript API in .js files
  4. Register the extension in runtime/worker.rs
  5. Add tests

Performance Considerations

  • Extensions use #[op2(fast)] for optimized hot paths
  • Zero-copy operations with #[buffer] and #[arraybuffer]
  • Async operations return futures that integrate with Tokio
  • Resource pooling and caching where appropriate

Learn More

Explore individual extension documentation to learn about specific APIs and their implementations.

Build docs developers (and LLMs) love