AssemblyScript automatically loads and imports your built wasm files into index.js
.
// index.js
const fs = require("fs");
const loader = require("@assemblyscript/loader");
const imports = { /* imports go here */ };
const wasmModule = loader.instantiateSync(fs.readFileSync(__dirname + "/build/optimized.wasm"), imports);
module.exports = wasmModule.exports;
To run our compiled module we require index.js
and call our exported wasm function.
$ node
> const { minusOne } = require('./index.js');
> minusOne(2);
// 1