Quick demo showing QuickJS embedded in Go, with a small WebAssembly helper.
This repository demonstrates using fastschema/qjs to run JavaScript handlers inside Go HTTP routes,
and a tiny wazero-backed WebAssembly module for an add function.
The main goal of this experiment is to see how we can call functions exported by other WASM modules from the JavaScript that is executed by QuickJS.
- Exposes JS module functions from
server/handlers.jsas HTTP endpoints. - Uses a pool of QuickJS runtimes for concurrency.
- Builds a small WebAssembly module (
server/add/main.wasm) and useswazeroto call it from Go.
- Go 1.25+ (confirm with
go version) bashfor runningbuild.sh(or run the commands manually)
-
Build the project and the WASM module:
./build.sh
-
Run the server:
# server listens on :8080 ./bin/server -
Try the endpoints in your browser or with
curl:curl http://localhost:8080/about curl http://localhost:8080/contact curl http://localhost:8080/hostname # Add with query parameters x and y curl "http://localhost:8080/add?x=5&y=7"
build.sh— convenience script that builds the WASM helper and server binary.server/— main server code.main.go— boots QuickJS, precompileshandlers.js, creates a runtime pool and registers HTTP routes.handlers.js— JavaScript module that exports handler functions used as HTTP endpoints.add.go— Go glue that loadsserver/add/main.wasmintowazeroand exposesAddto QuickJS.add/main.go— small Go file compiled to WASM; exportsadd.
bin/— output directory for the built server binary (bin/server)..cache/—wazerocache directory (created automatically).
- The server precompiles
handlers.jsand places exported functions under the globalhandlersobject. Each exported function becomes an HTTP route at/<functionName>. - Handler functions that expect arguments receive a single map built from URL query parameters. For example,
the
addhandler expectsxandy. - The WASM module
server/add/main.wasmis embedded into the Go binary using//go:embedinserver/add.go. Rebuild withbuild.shif you changeserver/add/main.go.
If you have questions about this demo, contact the repository owner.