Embed a JavaScript scripting engine into a Go application so users can write plugins or automation scripts in JS.
Run Babel or the TypeScript compiler from within a Go program without shelling out to Node.js.
Execute sandboxed JavaScript in a Go service with fine-grained control over what the script can access.
Build a Go CLI tool that accepts JavaScript configuration files or user-defined scripts.
Single goroutine per runtime, run one runtime instance per goroutine for concurrent use, values cannot be shared between runtimes.
Goja is a JavaScript engine written entirely in Go. It lets a Go program run JavaScript code directly, without needing to install a separate JavaScript runtime or rely on bindings to a native engine like V8. A developer embeds goja into their Go application and can then execute JavaScript strings, pass Go values into scripts, and get results back, all within the same process. The engine implements the ECMAScript 5.1 standard fully, meaning it can run the kind of JavaScript that was common before modern browser features like async/await. It can also run tools like Babel and the TypeScript compiler, which are themselves written in older-style JavaScript. Support for newer ES6 features such as arrow functions, classes, and modules is partially implemented and still in progress. The main reason to use goja instead of a wrapper around V8 is that goja has no native code dependencies. Because it is pure Go, it builds and runs anywhere Go runs, without special setup or cross-compilation complications. It also gives the host application fine-grained control over the JavaScript execution environment. The trade-off is speed: goja is faster than some other Go-based JavaScript engines but significantly slower than V8 for compute-heavy JavaScript work. The author recommends V8 if most of the actual logic lives in JavaScript. There are a few known behavioral differences from a browser environment. The setTimeout and setInterval functions are not included by default because they are not part of the ECMAScript standard and require an event loop, which the host application must provide. A companion project called goja_nodejs provides Node.js-compatible functionality including an event loop for applications that need it. Goja is not goroutine-safe, meaning a single runtime instance can only be used by one goroutine at a time. Multiple runtimes can run concurrently, but values cannot be passed between them.
← dop251 on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.