Space-Script and System Calls

I’m trying to get the value of the SB_FOLDER environment variable, what am I doing wrong?

silverbullet.registerFunction({name: "sbGetEnv"}, async (name) => {
  const env_var = await syscall("system.getEnv", name);
  return `${name}: ${env_var}`;
  //return $env_var;
})

```template
{{sbGetEnv(“SB_FOLDER”)}}
```

output:

SB_FOLDER: server

That’s not what getEnv does. It tells you whether your code is executing in the client or server, it doesn’t give access to environment variables. There’s no syscall for that in fact. It’s not completely trivial to add either. Perhaps it’s best to create a GitHub issue so we can also talk use cases.

Ahhh…makes sense. It’s the SB env rather than the underlying system. I thought it would behave more like:

console.log(Deno.env.get(“SB_FOLDER”).toString());

I’m just playing around right now. No actual “use case”. I prbably should have dug deeper into getEnv() before assuming I knew what it does!

1 Like