How can I get environment variables in wasm js? I ...
# webassembly
s
How can I get environment variables in wasm js? I assume that accessing the js side of
process.env
is necessary, but the interop of the
js
function requires a static string, so I'm not seeing how to properly access it via js interop.
e
Copy code
fun getenv(name: String): String = js("process.env[name] ?? ''")
s
Thanks for the response! No matter what it's not happy though:
Copy code
fun getenv(name: String): String? {
    return js("process?.env?.[name]")
}
Copy code
Calls to 'js(code)' should be a single expression inside a top-level function body or a property initializer in Kotlin/Wasm.
This is just a function in a file, so I'm not seeing how we aren't meeting this criteria.
e
use
=
and I think
?
return doesn't work
m
I hope that doesn’t work for
wasmJs
😱
o
Here is how I've implemented it in ktor not so long ago
🙌 1