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
Tumbzilla
Tumbzilla16mo ago
how are you accessing the environment variables? are you doing so via the Env object passed into the worker at runtime?
stormcph
stormcphOP16mo ago
um as i said, im pretty new to it. so im not completely sure, i'm diong it like its saying in the doc
Tumbzilla
Tumbzilla16mo ago
Do you have some sample code we could take a look at? Might help in figuring out what’s wrong
stormcph
stormcphOP16mo ago
okay, please dont judge the code i made, it may look stupid in your eyes...
export default {
async fetch(request, env, context) {
const {
ENV_SERVICE_ACCOUNT_EMAIL: SERVICE_ACCOUNT_EMAIL,
ENV_PRIVATE_KEY_PEM: PRIVATE_KEY_PEM,
ENV_TOKEN_URL: TOKEN_URL,
ENV_SHEET_ID: SHEET_ID,
ENV_RANGE: RANGE,
ENV_SERVER_HASH: SERVER_HASH
} = env;
export default {
async fetch(request, env, context) {
const {
ENV_SERVICE_ACCOUNT_EMAIL: SERVICE_ACCOUNT_EMAIL,
ENV_PRIVATE_KEY_PEM: PRIVATE_KEY_PEM,
ENV_TOKEN_URL: TOKEN_URL,
ENV_SHEET_ID: SHEET_ID,
ENV_RANGE: RANGE,
ENV_SERVER_HASH: SERVER_HASH
} = env;
that was just a small snippet of my code where i try to define the variables within my worker.js
Tumbzilla
Tumbzilla16mo ago
Ok great. What’s in your wrangler.toml?
stormcph
stormcphOP16mo ago
um, i only have the worker.js (im working within the web browser editor with the cloudflare worker)
stormcph
stormcphOP16mo ago
No description
Tumbzilla
Tumbzilla16mo ago
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 …
stormcph
stormcphOP16mo ago
they are, also sorry for long response i went to bed.
No description
Tumbzilla
Tumbzilla16mo ago
Are you running the worker locally or deployed?
stormcph
stormcphOP16mo ago
deployed i tried doing it like this, also note that the "variable" is just a placeholder for the actual names of the variable
const VARIABLE = self['VARIABLE'];
const VARIABLE = self['VARIABLE'];
also there are multiple but for this example we only ned to display one
Want results from more Discord servers?
Add your server