Detecting worker environments


What’s the best approach to use wrangler dev and wrangler preview and detect the environment?

In both cases I get ENVIRONMENT is not defined. Since both command force a KV preview_id, there must be a way to determine the mode, no?


1 Like

The docs are a little misleading with the ENVIRONMENT variable… You have to define the ENVIRONMENT var yourself using the vars key like so:

vars = { ENVIRONMENT = "production"}

vars = { ENVIRONMENT = "dev" }
vars = { ENVIRONMENT = "staging" }

I’ve opened a PR here to update the documentation.


They are indeed a bit confusing. Thanks for the PR!