worker environment variables, please help :)
I am pretty new to Cloudflare workers, I am using it for a personal app. my problem is that when i try to access my environment variables inside of the worker i simply get an error. now im pretty sure that its because im using javascript and not typescript, can anyone help me? thanks!
(the doc i read that sadly didnt work) https://developers.cloudflare.com/workers/configuration/environment-variables/
Environment variables · Cloudflare Workers docs
Attach text strings and JSON values as environment variables to your Worker. Environment variables are available on the env parameter passed to your …
11 Replies
how are you accessing the environment variables? are you doing so via the Env object passed into the worker at runtime?
um as i said, im pretty new to it. so im not completely sure, i'm diong it like its saying in the doc
Do you have some sample code we could take a look at? Might help in figuring out what’s wrong
okay, please dont judge the code i made, it may look stupid in your eyes...
that was just a small snippet of my code
where i try to define the variables within my worker.js
Ok great. What’s in your wrangler.toml?
um, i only have the worker.js (im working within the web browser editor with the cloudflare worker)
see https://developers.cloudflare.com/workers/configuration/environment-variables/#add-environment-variables-via-the-dashboard on how to set environment variables via the dashboard. Are all your environment variables visible via the worker settings menu?
Environment variables · Cloudflare Workers docs
Attach text strings and JSON values as environment variables to your Worker. Environment variables are available on the env parameter passed to your …
they are, also sorry for long response i went to bed.
Are you running the worker locally or deployed?
deployed
i tried doing it like this, also note that the "variable" is just a placeholder for the actual names of the variable
also there are multiple but for this example we only ned to display one