Denox embeds a TypeScript/JavaScript runtime (Deno/V8) into Elixir via a Rustler NIF.
Telemetry Events
Denox emits the following telemetry events:
[:denox, :eval, :start]— emitted before evaluating code- Measurements:
%{system_time: integer} - Metadata:
%{type: atom}— type is the function name atom (e.g.:eval,:eval_ts,:eval_async,:eval_ts_async,:eval_module,:eval_file,:eval_file_async,:call,:call_async,:eval_async_decode,:eval_ts_async_decode,:eval_file_async_decode,:call_async_decode) Note: sync*_decodevariants (:eval_decode,:call_decode, etc.) emit the base type (:eval,:call, etc.) since they delegate to the base function.
- Measurements:
[:denox, :eval, :stop]— emitted after successful evaluation- Measurements:
%{duration: integer}(native time units) - Metadata:
%{type: atom}
- Measurements:
[:denox, :eval, :exception]— emitted on evaluation error- Measurements:
%{duration: integer} - Metadata:
%{type: atom, kind: :error, reason: term}
- Measurements:
Summary
Functions
Await the result of an async evaluation task.
Call a named JavaScript function with arguments.
Call a named async JavaScript function with arguments, returning a Task.
Call a named async JavaScript function and decode the JSON result.
Call a named JavaScript function and decode the JSON result.
Create a V8 snapshot from setup code.
Evaluate JavaScript code in the given runtime.
Evaluate JavaScript code as an ES module, returning a Task.
Evaluate JavaScript code asynchronously and decode the JSON result.
Evaluate JavaScript code and decode the JSON result to Elixir terms.
Read and evaluate a JavaScript or TypeScript file.
Read and evaluate a JavaScript or TypeScript file asynchronously.
Read and evaluate a JavaScript or TypeScript file asynchronously and decode the JSON result.
Read and evaluate a JavaScript or TypeScript file and decode the JSON result.
Load and evaluate an ES module file. Supports .ts/.js with import/export.
Evaluate TypeScript code in the given runtime. Transpiles via deno_ast/swc then evaluates. No type-checking.
Evaluate TypeScript code as an ES module, returning a Task.
Evaluate TypeScript code asynchronously and decode the JSON result.
Evaluate TypeScript code and decode the JSON result to Elixir terms.
Execute JavaScript code, ignoring the return value.
Execute TypeScript code, ignoring the return value.
Create a new JavaScript runtime.
Types
@type runtime() :: reference()
Functions
Await the result of an async evaluation task.
Delegates to Task.await/2. Use with tasks returned by
eval_async/2, eval_ts_async/2, call_async/3, and call_async_decode/3.
Example
Denox.eval_async(rt, "export default await Promise.resolve(42)")
|> Denox.await()
#=> {:ok, "42"}
Call a named JavaScript function with arguments.
Arguments are serialized to JSON. Returns {:ok, json_string} or {:error, message}.
Call a named async JavaScript function with arguments, returning a Task.
Use Task.await/2 to get the result.
Returns a Task that resolves to {:ok, json_string} or {:error, message}.
Call a named async JavaScript function and decode the JSON result.
Returns a Task that resolves to {:ok, term()} or {:error, term()}.
Call a named JavaScript function and decode the JSON result.
Create a V8 snapshot from setup code.
The snapshot captures all global state (variables, functions, etc.) after executing the setup code.
Snapshot compatibility
Custom V8 snapshots created by create_snapshot/2 are not compatible
with the deno_runtime MainWorker backend currently used by Denox.runtime/1.
Passing a snapshot via runtime(snapshot: bytes) will emit a warning and the
snapshot will be ignored. Use Denox.eval/3 or Denox.exec/3 to run
initialization code instead.
Options:
:transpile- if true, transpile TypeScript before executing (default: false)
Returns {:ok, snapshot_bytes} or {:error, message}.
Evaluate JavaScript code in the given runtime.
Pumps the event loop and resolves Promises automatically.
Supports import(), setTimeout, and other async operations.
Returns {:ok, json_string} or {:error, message}.
Evaluate JavaScript code as an ES module, returning a Task.
The code is evaluated as a proper ES module, so static import/export
declarations and top-level await work natively. Use export default
to return a value.
Returns a Task that resolves to {:ok, json_string} or {:error, message}.
Example
task = Denox.eval_async(rt, "const status = (await fetch('https://httpbin.org/get')).status; export default status;")
{:ok, "200"} = Task.await(task)
# Static imports work:
task = Denox.eval_async(rt, """
import { something } from './my_module.js';
export default something;
""")
Evaluate JavaScript code asynchronously and decode the JSON result.
Returns a Task that resolves to {:ok, term()} or {:error, term()}.
Evaluate JavaScript code and decode the JSON result to Elixir terms.
Read and evaluate a JavaScript or TypeScript file.
Simpler than eval_module/2 — no import/export support, just script execution.
TypeScript files (.ts, .tsx) are automatically transpiled.
Returns {:ok, json_string} or {:error, message}.
Read and evaluate a JavaScript or TypeScript file asynchronously.
Returns a Task that resolves to {:ok, json_string} or {:error, message}.
Read and evaluate a JavaScript or TypeScript file asynchronously and decode the JSON result.
Returns a Task that resolves to {:ok, term()} or {:error, term()}.
Read and evaluate a JavaScript or TypeScript file and decode the JSON result.
Returns {:ok, term()} or {:error, term()}.
Load and evaluate an ES module file. Supports .ts/.js with import/export.
Returns {:ok, "undefined"} or {:error, message}.
Evaluate TypeScript code in the given runtime. Transpiles via deno_ast/swc then evaluates. No type-checking.
Pumps the event loop and resolves Promises automatically.
Returns {:ok, json_string} or {:error, message}.
Evaluate TypeScript code as an ES module, returning a Task.
Supports static import/export declarations and top-level await.
Use export default to return a value.
Returns a Task that resolves to {:ok, json_string} or {:error, message}.
Evaluate TypeScript code asynchronously and decode the JSON result.
Returns a Task that resolves to {:ok, term()} or {:error, term()}.
Evaluate TypeScript code and decode the JSON result to Elixir terms.
Execute JavaScript code, ignoring the return value.
Returns :ok or {:error, message}.
Execute TypeScript code, ignoring the return value.
Returns :ok or {:error, message}.
Create a new JavaScript runtime.
Options:
:base_dir- base directory for resolving relative module imports:sandbox- (deprecated) if true, deny all permissions. Use:permissionsinstead:permissions- permission mode::all— allow everything (default):none— deny everything (same assandbox: true)- keyword list — granular permissions. Supports both
allow_*anddeny_*keys. E.g.[allow_net: true, allow_read: ["/tmp"], deny_env: true]. Values can betrue(blanket) or a list of strings (specific paths/hosts).falseentries are ignored. Unknown keys raiseArgumentError.
:cache_dir- on-disk cache directory for remote module fetches:import_map- map of bare specifiers to resolved URLs/paths (e.g.%{"lodash" => "https://esm.sh/lodash"}):callback_pid- PID of the process that handles JS→Elixir callbacks (enablesDenox.callback()in JS):snapshot- V8 snapshot binary for faster cold start (created viacreate_snapshot/2)
Returns {:ok, runtime} or {:error, message}.