KV foundations
Create and bind a namespace
Connect a named Worker binding to a KV namespace and keep local and production data targets explicit.
8 minute lesson
A KV namespace is the administrative container. The binding name is the JavaScript property your Worker uses, such as env.CONFIG.
Wrangler local development uses local state by default. A remote binding connects development to Cloudflare state and must be an explicit choice. Regenerate Worker types after adding or renaming the binding.
Create a practice namespace, add a CONFIG binding, run wrangler types, and verify a local write does not appear in production.
Create separate local and production names deliberately:
npx wrangler kv namespace create FLAGS
npx wrangler kv key put --binding FLAGS checkout_enabled true --remote
npx wrangler kv key get --binding FLAGS checkout_enabled --remote
Inspect the generated namespace ID before adding it to configuration. Never use a production namespace as disposable local state. Delete the practice key when the exercise ends, but keep the namespace if another environment binding depends on it.
Lesson completed