18 · Modules
JavaScript / TypeScript · Node
Use JavaScript and TypeScript through embedded Node, including native modules and Promises. The shim, runtime and addon ABI must match. Zolo int uses bigint in inline signatures.
On this page
Run locally with the matching plugin and runtime. These examples do not run in the browser playground.
JavaScript / TypeScript / Node.
// JavaScript and TypeScript use the same embedded Node runtime.
use plugin node::{javascript as js, typescript as ts}
extern js fn add(a: int, b: int) -> int {
return a + b;
}
extern ts {
fn normalize(text: str) -> str {
return text.trim().toLowerCase();
}
fn root(value: float) -> float {
return Math.sqrt(value);
}
}
let original = " Zolo "
let greeting: str = extern js {
return `Hi ${`${original.trim()}`}`;
}
let lexical: bool = extern js {
// Braces and slashes in native literals remain inside this body.
return /[{}\/]/.test("}") && `literal } ${original.trim()}`.endsWith("Zolo");
}
extern ts fn native_import() -> str {
import { createHash } from "node:crypto";
return createHash("sha256").update("Zolo").digest("hex").slice(0, 8);
}
print(add(20, 22))
print(normalize(original))
print(root(81.0))
print(greeting)
print(lexical)
print(native_import().len())
// expected:
// 42
// zolo
// 9
// Hi Zolo
// true
// 8
Requires the Zolo CLI/host — open in the playground or run locally.
Preparation and deployment
Source-free packaging can retain prepared foreign artifacts, but does not remove runtime or platform dependencies. VM, native and LLVM hosting are covered; foreign bindings reject unsupported WebAssembly targets. The recent provider acceptance covers Windows x64. Python acceptance specifically covers CPython 3.12; other platforms need their own verification.