Why env is only limited to fetch request? I'd like to know the technical reason behind it...

Why?
9 Replies
Hard@Work
Hard@Work3mo ago
What do you mean? It should also be present on other events, like the Email and Scheduled Handlers
0x146231489231923
0x146231489231923OP3mo ago
I mean inside cloudflare workers you cant access it from anywhere with process.env...
Hard@Work
Hard@Work3mo ago
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
0x146231489231923
0x146231489231923OP3mo ago
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
Hard@Work
Hard@Work3mo ago
Yeah, though note that this can break things
0x146231489231923
0x146231489231923OP3mo ago
whats the difference with asynclocalstorage btw looks like u use cf worker alot? u know a lot, even AsyncLocalStorage
Hard@Work
Hard@Work3mo ago
AsyncLocalStorage scopes your env to the Request, so that you only have access to the variables/bindings you should have access to
0x146231489231923
0x146231489231923OP3mo ago
any link that i read up?
Hard@Work
Hard@Work3mo ago
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.
Want results from more Discord servers?
Add your server