explaingit

dop251/goja

6,864GoAudience · developerComplexity · 3/5Setup · moderate

TLDR

Goja is a pure-Go JavaScript engine that lets you run JavaScript code inside a Go application with no native dependencies, no Node.js, no V8, no CGO, just import and execute JS directly from Go.

Mindmap

mindmap
  root((goja))
    What it does
      JS engine in Go
      No native deps
      Embed scripting
    Capabilities
      ES5.1 full support
      Partial ES6
      Run Babel
    Limitations
      Slower than V8
      Single goroutine
      No setTimeout built-in
    Audience
      Go developers
      Plugin builders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Embed a JavaScript scripting engine into a Go application so users can write plugins or automation scripts in JS.

USE CASE 2

Run Babel or the TypeScript compiler from within a Go program without shelling out to Node.js.

USE CASE 3

Execute sandboxed JavaScript in a Go service with fine-grained control over what the script can access.

USE CASE 4

Build a Go CLI tool that accepts JavaScript configuration files or user-defined scripts.

Tech stack

GoJavaScriptECMAScript 5.1

Getting it running

Difficulty · moderate Time to first run · 30min

Single goroutine per runtime, run one runtime instance per goroutine for concurrent use, values cannot be shared between runtimes.

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to embed goja into my Go application, run a JavaScript string, and get the result back as a Go value.
Prompt 2
Using goja, expose a Go struct as an object in JavaScript so a user script can call my Go functions directly.
Prompt 3
How do I run Babel transpilation inside a Go program using goja, how do I load the Babel source and pass code through it?
Prompt 4
Help me implement a basic event loop for goja using the goja_nodejs companion package so I can use setTimeout in embedded scripts.
Prompt 5
What ES6 features does goja support today and what do I need to polyfill for modern JavaScript to run correctly?
Open on GitHub → Explain another repo

← dop251 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.