简体   繁体   中英

How can I run a “hello world” on webassembly with the latest Node.js?

I'm making this question after reading the official documentation and not finding this information.

I'm on Node.js v8.1.3 . How do I compile and run a "hello world" on wast (WebAssembly's textual representation) from within JavaScript on Node.js?

Use node-wasm to load your wasm file and then in your node js app, do this:

import loadWasm from 'node-wasm';

async function run() {
  const {rust_function} = await loadWasm('/local/path/to/wasm');
  const result = rust_function();
  console.log(result);
}

run();

There's a complete example here in the same repo. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM