Prerequisites
- Node.js (tested with v14.18.2)
- Emscripten SDK with
emccavailable in yourPATH
Before you begin, make sure you’ve installed Node.js and set up the Emscripten SDK.
Run
Run
emcc --version to verify your installation.1. Write the C Source
Create a file namedhelloworld.c with the following contents:
2. Compile to WASM for Node.js
Use Emscripten’semcc compiler to generate both the WebAssembly binary and the JavaScript loader:
| File | Description |
|---|---|
| helloworld.js | JavaScript “glue” code that locates, loads, and runs the WASM asset |
| helloworld.wasm | Compiled WebAssembly module |
helloworld.js looks like this: