This code will take a wat file (main.wat), compile it to wasm, then instantiate the wasm. This code requires the package .
$> npm init
$> npm install wabt
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
});