# Detecting worker environments

Hi!

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?

Thanks!

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"}

[env.dev]
vars = { ENVIRONMENT = "dev" }
[env.staging]
vars = { ENVIRONMENT = "staging" }
``````

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

4 Likes

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