Node.js WebAssembly
WebAssembly can execute compiled modules from Node, but useful integration still depends on an explicit import/export interface and the module’s provenance.
How it works
This fixed teaching module exports one integer addition function and imports no host capabilities. Its bytes are included directly so the example needs no compiler installation or download. A real module may require memory, tables or imported functions whose permissions matter. Successful compilation does not establish that an arbitrary module is safe, fast or appropriate for untrusted public execution.
Run the code
Run this example locally with Node.js. The exact sources are reviewed on Node 22.15.1 and Node 24.22.1 unless a specialised lab states otherwise. Save the complete source as webassembly.mjs in a separate empty exercises folder and run node webassembly.mjs. There is no Node.js browser runner on Bhylu; the plain JavaScript playground does not provide these filesystem, server or process APIs.
Download the complete source. Ordinary Node scripts need no Apache, PHP or MySQL service. File examples own their temporary folders; network fixtures use loopback and available temporary ports.
Example
const bytes = new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127, 1, 127, 3, 2, 1, 0, 7, 7, 1, 3,
97, 100, 100, 0, 0, 10, 9, 1, 7, 0, 32, 0, 32, 1, 106, 11,
]);
const { instance } = await WebAssembly.instantiate(bytes, {});
console.log(instance.exports.add(2, 3));
console.log(WebAssembly.validate(bytes));
Expected result
5 true
The fixed module validates and returns the expected integer result. There is no timing comparison with JavaScript and no claim that this tiny computation benefits from compilation. The example demonstrates the host interface rather than a production acceleration strategy.
Use the Node.js API reference for the precise version contract.