Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Deno 8 min read How-to mediumAdept

Roll your own JavaScript runtime

A minimal JavaScript runtime called runjs can be built in Rust by combining the deno_core crate, which wraps a V8 isolate in a JsRuntime, with a single-threaded tokio runtime as the event loop. The tutorial loads and evaluates ES modules from disk, adds a console API in a bundled runtime.js, and exposes async and sync filesystem functions to JavaScript via #[op2] ops registered through the extension! macro. deno_core handles marshalling between JS Promises and Rust Futures, so each new native API needs only a small amount of glue code.

Related posts

  • Roll your own JavaScript runtime, pt. 3

    Deno mediumAdept

    V8 startup snapshots can speed up launch of a custom deno_core-based JavaScript runtime at a typically negligible cost in binary size. A Cargo build.rs script uses deno_core's extension! macro and create_snapshot with CreateSnapshotOptions to serialize the runtime.js extension into RUNJS_SNAPSHOT.bin in OUT_DIR. main.rs then embeds the snapshot with include_bytes!, passes it as startup_snapshot in RuntimeOptions, and switches the extension to init_ops() so only the Rust ops are registered at runtime.

  • Roll your own JavaScript runtime, pt. 2

    Deno mediumAdept

    A custom JavaScript runtime built on deno_core gains three capabilities: a fetch op backed by the reqwest crate and registered in the runjs extension, a CLI that takes the script path as its first argument, and TypeScript/TSX support. TypeScript support comes from a custom TsModuleLoader that implements deno_core's ModuleLoader trait. It picks a MediaType from the file extension and uses deno_ast to parse and transpile TS, TSX and JSX into JavaScript before handing the module to JsRuntime. The whole runtime stays around 154 lines of Rust.

  • Deno's Other Open Source Projects

    Deno easyNovice

    Deno publishes many MIT-licensed supporting libraries extracted from its runtime, most of them Rust crates. Highlights include rusty_v8 (zero-overhead Rust bindings to V8's C++ API), deno_core (ops and an event loop mapping JS Promises to Rust Futures), rust-urlpattern, import_map, eszip (a streamable single-file format for serialized module graphs, used by Deno Deploy), sui (embedding data in ELF/PE/Mach-O executables while keeping them code-signable), dnt (Deno-to-npm transform), wasmbuild, the monch parser combinator library, deno_task_shell, the flaky_test macro, and vnotify (detecting changes across millions of S3 objects via hashed notification keys). Most entries come with short usage examples.

  • Wrapping My Mind Around Node.js Runtimes

    Neon easyNovice

    Deno and Bun take different approaches to replacing Node.js as a server-side JavaScript runtime. Deno, built by Node's creator, focuses on security with a permission sandbox, built-in TypeScript and web-standard APIs. In Deno 2 it has moved away from URL imports toward the JSR registry and Node compatibility. Bun runs on JavaScriptCore, aims for speed, and bundles a package manager, test runner, bundler, embedded SQLite and automatic .env loading. The recommendation: Node.js for long-lived projects, Deno when security or Deno Deploy matters, and Bun when performance is the priority, or just as a fast package manager, as Neon does for neonctl.

  • Deno 1.20 Release Notes

    Deno mediumAdept

    Deno 1.20 cuts JavaScript-to-Rust op call overhead by up to ~60% by using Rust proc macros to generate a dedicated V8 binding per op, eliminating op routing and skipping deserialization of unused arguments; a 1 MB base64 roundtrip drops from ~125 ms to ~3.3 ms. The release also adds automatic gzip/brotli compression of non-streamed HTTP responses, an unstable `deno bench` subcommand (1000 warmup plus 1000 measured iterations by default), and a cross-platform `deno task` runner using a POSIX-like shell subset. Other changes include import maps in the config file, in-memory TLS certs, `Deno.upgradeHttp()`, FFI global statics, opt-in `--trace-ops` for test leak tracing (made opt-in because of a performance regression), `AbortSignal.timeout()`, and stricter default permissions for tests and workers, plus TypeScript 4.6 and V8 10.0.

The quest for software engineering knowledge.

Look:
Layout: