Global vars
Hello, I'm trying to find the most convenient approach to pass keys into internal clients and other env values previously provided via
process.env.NAME
. I stumbled across this mention in docs: https://developers.cloudflare.com/workers/wrangler/environments/#:~:text=Any%20defined%20environment%20variables%20(the%20vars%20key)%20are%20exposed%20as%20global%20variables%20to%20your%20Worker.
Does it work? Variables specified in wrangler.toml are accessible via env.NAME param but they don't seem globally accessible as the snippet in the docs.Environments · Cloudflare Workers docs
Deploy the same Worker application with different configuration for each environment.
4 Replies
They were global on legacy Service Workers
Module Workers only have them on
env
Thanks for the clarification!
You could use https://developers.cloudflare.com/workers/runtime-apis/nodejs/ to expose a
process
that you can import & set values on (https://developers.cloudflare.com/workers/runtime-apis/nodejs/process/) or use the Wrangler define
option to do build-time constants, depending on if these values are secrets or not.Does it impact worker's performance when I opt-in to node compatibility?
I see that the process needs to be imported and env values copied. How is it different from creating a module with custom
export const env = {};
?