Why env is only limited to fetch request? I'd like to know the technical reason behind it...
Why?
9 Replies
What do you mean? It should also be present on other events, like the Email and Scheduled Handlers
I mean inside cloudflare workers
you cant access it from anywhere with
process.env...
Ooh. Basically, it allows the Worker to switch your environment variables around while it is still running
If you want access to Variables/Bindings without passing
env
around manually, you can use AsyncLocalStorage
do u have any implementation by yourself?
i also exploring that
but after that i realise i could just assign all the env into a global var and then access it from anywhere
Yeah, though note that this can break things
whats the difference with asynclocalstorage
btw looks like u use cf worker alot?
u know a lot, even
AsyncLocalStorage
AsyncLocalStorage scopes your
env
to the Request, so that you only have access to the variables/bindings you should have access toany link that i read up?
Cloudflare Docs
AsyncLocalStorage | Cloudflare Workers docs
Cloudflare Workers provides an implementation of a subset of the Node.js AsyncLocalStorage ↗ API for creating in-memory stores that remain coherent through asynchronous operations.