1. c-shared build
Building Go with -buildmode=c-shared emits a .so plus a C header, callable through an FFI like ffi-napi.
// go build -buildmode=c-shared -o lib.so main.goTyporithm · hard
Step 1 of 8 · intro card
Native Integrations
Go can expose functions to Node by building with -buildmode=c-shared (a .so plus header) consumed through an FFI like ffi-napi. Alternatively, compile Go, Rust, or C to WebAssembly and run it via the WebAssembly API — sandboxed, cross-platform, no per-OS native build. WASM trades some speed and syscall access for portability: choose c-shared/addons for raw speed and full OS access, WASM for portability and sandboxing.
Go does not link into Node the way C++ or Rust addons do, but it can build a C-compatible shared library with go build -buildmode=c-shared, producing a .so and a header. Node then calls it through a foreign-function interface like ffi-napi, which dlopens the library and marshals arguments.
The other path is WebAssembly: compile Go (or Rust or C) to a .wasm module and run it with the WebAssembly API. WebAssembly.instantiate compiles the bytes and links them, and the exported functions hang off instance.exports — one portable artifact that runs on any OS with no native build per platform.
The trade-off is architectural. c-shared/native addons give raw speed and full operating-system access (files, sockets, syscalls) but must be compiled per platform and run with the host's privileges. WASM runs in a sandbox with limited syscall access and a small speed cost, but it is portable and isolated — pick by whether you value speed and OS access or portability and safety.
go build -buildmode=c-shared emits a .so + header for FFI.
WebAssembly.instantiate runs portable .wasm in Node.
c-shared = speed + OS access; WASM = portability + sandbox.
// Go: build a C-shared library
// go build -buildmode=c-shared -o lib.so main.go
// Or compile to WASM and run in Node
const wasm = await WebAssembly.instantiate(bytes);
const { add } = wasm.instance.exports;
console.log(add(2, 3));Connect each part of the code to the concept before you type.
Building Go with -buildmode=c-shared emits a .so plus a C header, callable through an FFI like ffi-napi.
// go build -buildmode=c-shared -o lib.so main.goWebAssembly.instantiate compiles and links a .wasm module from its bytes — portable across OSes with no native build.
const wasm = await WebAssembly.instantiate(bytes);Exported WASM functions appear on instance.exports, ready to call from JavaScript.
const { add } = wasm.instance.exports;Calling the exported add runs inside the WASM sandbox and returns a number to JS.
console.log(add(2, 3));Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.