Live data from Hacker News

Goja: A Golang JavaScript Runtime

jtarchie.com

31–36 of 36 posts

Re: Goja: A Golang JavaScript Runtime

#31
post #9

The examples in the article seem awfully contrived. Can someone please explain what a real-world use case for something like this would be? Why not just do it all in Go? Or is the point of it to be able to use existing JS scripts within a Go application?

On top of the previous comments describing how to use JS as an embedded scripting language, I've seen in production (series B startup) an architecture where:

a) non-technical users describe, in plain English, what they would like from the data; b) an LLM with lots and lots of prompt-engineering massaging translates the English into JS, c) the JS gets executed in a sandbox, d) the results get returned to the user

Re: Goja: A Golang JavaScript Runtime

#32
post #9

The examples in the article seem awfully contrived. Can someone please explain what a real-world use case for something like this would be? Why not just do it all in Go? Or is the point of it to be able to use existing JS scripts within a Go application?

I didn't use Goja (this was maybe a decade ago) but I used Otto, which is the same concept.

I used it for game scripting. Lots of stuff is just easier to write in a high level language. I was able to use inheritance to compose behaviors for entities, and I could restart entities with new code without having to restart the server.

Re: Goja: A Golang JavaScript Runtime

#33
You know, back when I got started as a Schemer, I remember people complaining about how many implementations of Scheme there were and how difficult it was to port between them. Today in JavaScript land we have Node, Deno, Bun, Goja, Sobek, Nashorn, whatever the browsers have, QML, GNOME, all of them subtly different. But instead of complaining, which people seem inclined to do when they encounter nested parens, people bro down and wrote code necessary to make them all interoperate if necessary -- despite JS having even less of a core language standard than Scheme does.

I guess it's the Lisp Curse or something, I dunno.

Re: Goja: A Golang JavaScript Runtime

#34

This is the runtime pocketbase uses to allow javascript interop. Pocketbase is the framework that makes me want to switch to golang. It just makes a lot of sense. One thing that concerned me, though. How do I debug goja? It doesn't seem like I can set breakpoints as usual. https://pocketbase.io/

PocketBase is a ton of fun. I’ve been using it for building my business’s store, and integrating with stripe was such a breeze. I’m using it sort of like a headless CMS/store. I considered other things like Payload CMS (which is awesome too) but the simplicity and productivity of pocket was such a draw. I don’t regret it.

Re: Goja: A Golang JavaScript Runtime

#35

I work on the D2 project ([0]) and we switched from other Javascript runners (v8go) to Goja. Using a JS runtime with a dependency on cgo means your Go program loses the (huge) benefit of cross-compiling to different architectures, since at build time it gets linked to the current system's libc. If you're interested in some production code with Goja, this is our code for calling RoughJS ([1]) from Go in order to produ…

It is quite easy to cross-compile cgo program to most architectures - just use Zig for this:

  CC="zig cc -target aarch64-linux"

Re: Goja: A Golang JavaScript Runtime

#36
post #15

I just dug through a lot of the issues and PRs in Goja, and eventually found that the grafana/k6 team recently forked Goja as Sobek [1], because the Goja dev has not been able to dedicate sufficient time to their PRs - namely ES Modules support [2], which was one of the only modern (ES6+) JS features outstanding [3] So, Sobek seems to be the way forward... [1] https://github.com/grafana/sobek/ [2] https://github.com/…

While I'm sure Goja is great for just JavaScript, using something like wazero allows your app to support more languages (anything that compiles to WASM) while keeping the benefits of CGO.

https://wazero.io/

I've used Wazero myself on C++ -> WASM code but I'm sure you could use Emscripten or something to compile JavaScript to WASM.

Post reply on HN