Hello World
Setup Instructions
Step-By-Step Guide
$ cd <some_development_directory>$ mkdir wasmer-js-node-hello-world $ cd wasmer-js-node-hello-world $ npm init$ npm install --save @wasmer/wasi- Important Difference
const fs = require("fs") const { WASI } = require("@wasmer/wasi") const nodeBindings = require("@wasmer/wasi/lib/bindings/node") const wasmFilePath = "./helloworld.wasm" // Instantiate a new WASI Instance let wasi = new WASI({ args: [wasmFilePath], env: {}, bindings: { ...(nodeBindings.default || nodeBindings), fs: fs } }) // Async function to run our Wasm module/instance const startWasiTask = async pathToWasmFile => { // Fetch our Wasm File let wasmBytes = new Uint8Array(fs.readFileSync(pathToWasmFile)).buffer // Instantiate the WebAssembly file let wasmModule = await WebAssembly.compile(wasmBytes); let instance = await WebAssembly.instantiate(wasmModule, { ...wasi.getImports(wasmModule) }); // Start the WASI instance wasi.start(instance) } // Everything starts here startWasiTask(wasmFilePath) $ node index.js Hello World!
Last updated