Nodejs WAT Compiler

This code will take a wat file (main.wat), compile it to wasm, then instantiate the wasm. This code requires the package WABT.

Setup

$> npm init
$> npm install wabt

Code (index.js)

var { readFileSync } = require("fs");
var wabt = require("wabt")();

var inputWat = "main.wat";
var wasmModule = wabt.parseWat(inputWat, readFileSync(inputWat, "utf8"));
var importObject = { };

WebAssembly.instantiate(wasmModule.toBinary({}).buffer, importObject).then(function(res) {
    //run functions here
  });

Last updated

Was this helpful?