Previous: , Up: Deployment   [Contents][Index]


4.2 NodeJS deployment

Deploying to NodeJS is similar to web deployment but without all the web server setup. A small boot script is needed to import the reflect.js library (see JavaScript reflection) and then load the Wasm binary.

For example, here’s a small boot script that imports reflect.js, calls Scheme.load_main to load the Wasm binary, imports the document.findElementById method, and prints the program output:

let hoot = await import("reflect.js");
let results = hoot.Scheme.load_main("example.wasm", {
  reflect_wasm_dir: ".",
  user_imports: {
    document: {
      findElementById: (id) => document.findElementById(id)
    }
  }
});
console.log(results);

The necessary runtime files can be found in the $prefix/share/guile-hoot/ directory, where $prefix is the directory where Hoot was installed on your system. This is typically /usr or /usr/local on Linux distributions such as Debian, Ubuntu, Fedora, etc.

The runtime files can be copied to the current directory like this:

cp $prefix/share/guile-hoot/$version/reflect-js/reflect.js .
cp $prefix/share/guile-hoot/$version/reflect-wasm/*.wasm .

Once the necessary files are in place, running the program is simple:

node boot.js