repositorypackage
2.3.13+incompatible
Repository: https://github.com/jdxcode/gode.git
Documentation: pkg.go.dev
# README
gode
gode runs a sandboxed node installation to run node code and install npm packages.
Usage
Gode will autoinstall Node and npm if it's not in the specified working directory.
To use gode, first give it a working directory. In this case, ~/.gode
. You would need to already have a homeDir variable for this to work.
c := NewClient(filepath.Join(homeDir, ".gode"))
Next, call c.Setup()
to ensure that gode is setup properly in that working directory.
err := c.Setup()
if err != nil {
panic(err)
}
Finally, execute a node script. This returns an *os/exec.Cmd
:
output, err := c.RunScript(`console.log("hello world!")`).CombinedOutput()
if err != nil {
panic(err)
}
fmt.Println(string(output))
Or install packages:
err := c.InstallPackage("request")
if err != nil {
panic(err)
}