D
Deno

help

Using Deno to run JavaScript from Golang

Pparasocialfix9/7/2023
I just started looking into this, but I'm looking for something like rogchap.com/v8go but it would be cool if I could run Deno instead of v8 So far I'm just thinking of saving some code into a file and then exec.CommandContext with deno run myfile.ts 🙂 any help with how to find any solutions in this area would be appreciated 🙂 so far I only been able to find some experiments in rust like https://austinpoor.com/blog/js-in-rs
Explore how the Deno runtime can enable JavaScript code execution in a Rust application via a proof-of-concept project called "js-in-rs". Discover the flexibility and versatility of using JavaScript expressions as filters in a CLI, written in Rust, as a powerful alternative to regular expressions. Watch out grep!
DAHDeno AI Helper9/7/2023
The documentation does not provide a clear answer on how to run JavaScript from Golang using Deno. However, it does mention that Deno is built on top of deno_core, a Rust crate that can be used to embed a JavaScript runtime into your Rust application. This suggests that embedding Deno into other languages might be possible, but the specifics for Golang are not provided. As for your current approach of saving code into a file and then using exec.CommandContext with deno run myfile.ts, it seems like a viable solution as long as you handle the file creation, execution, and cleanup properly. For more advanced use cases, you might want to look into creating a custom JavaScript runtime using deno_core, as described in the "Roll your own JavaScript runtime" series in the documentation. However, this is demonstrated with Rust, not Golang. I recommend reaching out to the Deno community for more specific advice or examples related to Golang. 🦕
Bbartlomieju9/7/2023
There are only bindings for Rust if you want to create something from scratch; with Go you'd probably need to provide some kind of FFI boundary between Go and Rust. "Roll you own JavaScript runtime" blog post mentioned above is a good starting point
Pparasocialfix9/7/2023
Thanks for the reply, high level, what do you think of using some other mechanism to talk to it instead of ffi? Like rest calls or stdin/stdout
Bbartlomieju9/8/2023
Either works, and it really depends on what your trying to achieve and whether you want to use existing Deno binary or compile something yourself

Looking for more? Join the community!