> For the complete documentation index, see [llms.txt](https://augustus-pash.gitbook.io/wasm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://augustus-pash.gitbook.io/wasm/nodejs-compiler.md).

# 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](https://www.npmjs.com/package/wabt).

### Setup

```
$> npm init
$> npm install wabt
```

### Code (index.js)

```javascript
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
  });
```
