Do I need to store my environment variables in wrangler.toml?

Do env vars need to be defined in the wrangle.toml? I initially have the env var in .dev.vars, and manually added the value for the env var in the Cloudflare, however, whenever I deploy the worker, it overrides the env var I manually configured. The worker is a public github, and I would rather not have the env var exposed. I know I could just use a secret, I would rather have env vars seperate from the code.
8 Replies
Hello, I’m Allie!
Environment Variables defined within wrangler.toml overwrite anything defined on the Dashboard. The only thing that isn't overwritten are secrets, as they have to be pushed manually
terenced
terencedOP7mo ago
Initially, I did not have any env vars defined, but when I deployed, it cleared out the one I defined manually in the dashboard. It that expected?
Hello, I’m Allie!
Yes. When using a wrangler.toml, it is the single source of truth for how your Worker is configured
terenced
terencedOP7mo ago
OK, so after every deploy, i would need to go an set the env var in the dashboard again?
Hello, I’m Allie!
I’m not entirely sure why a Secret wouldn’t work here?
terenced
terencedOP7mo ago
it definitely can. I am just trying to understand how env vars work. It feels odd to me to have the env set in the code. I might as well just hardcode the value since I do not have multiple envs
Hello, I’m Allie!
Those variables are for things you don’t mind being public, for example an API URL. The token for said API might be a secret Two separate usecases, even though the end product is sort of similar
terenced
terencedOP7mo ago
Thank you
Want results from more Discord servers?
Add your server