feat: add node process.env builtin to access env vars#234
feat: add node process.env builtin to access env vars#234sd2k wants to merge 2 commits intobytecodealliance:mainfrom
Conversation
This uses wasi:cli/environment to get the environment variables provided by the host.
|
Hey, @andreiltd and I need this just like anyone will. Can't run in production without env vars for creds among other things and they can't be baked into the component, obvs. :-) We'll see about having a look next week some time. |
|
Thank you for the patch! We had a brief discussion about it during the last JS SIG community meeting. While the functionality is definitely useful, adding just this small portion of the Node API as a built‑in doesn’t feel quite right at this stage. A fully supported and currently working alternative for accessing environment variables with both import { getEnvironment } from 'wasi:cli/environment@0.2.3';
const entries = getEnvironment();
const env = Object.fromEntries(entries);
console.log(env.FOO);Let us know if you'd like help adapting your use case to this approach. |
|
I'm also interested in having Covering Those two features I'd argue are the minimum for a useful production workflow (respond to http requests and not hard code secrets) and by supporting them as built-ins lowers the new user barrier to entry quite a bit. You can make production useful tools without having to take on the cognitive load of understanding wasi imports, etc. and opt-in to those for more advanced workflows. Is there active opposition to supporting |
This uses wasi:cli/environment to get the environment variables provided by the host. The
process.envobject is a Proxy in this implementation so that we can callget_environmentlazily, which enables wizer to run.I needed this for a PoC so had Cursor help me out (it was surprisingly good) - it's probably not exactly the direction you want but I'm happy to iterate if it's in the right direction!
I think this relates to #188?