Now that we have our Workers project up and running, we need to create a KV namespace. A KV namespace is a key-value database that is replicated to Cloudflare's edge. Using the terminal, we will create our namespace and add it to our wrangler.toml file.
Instructor: [0:00] Now, to work with Workers KV, we need to start by creating a KV namespace. A KV namespace is the actual data store where all of our keys and values are stored. Basically, the two things we need to do are, first, create a new KV namespace, and then second, add it to our Workers Project using our wrangler.toml file.
[0:19] Open up the terminal and run wrangler kv:namespace create, and then give it a KV namespace name. I'll call this my_first_kv. You'll see it says, "Creating namespace with the title, my-kv-project-my_first_kv."
[0:36] The structure here is, your project name, which is my-kv-project, and then the name of the KV namespace itself, which is my_first_kv. The second part here says, "Success! Add the following to your configuration file, kv_namespaces," which is an array, and then, inside of that, this KV namespace object, which has a binding, my_first_kv, and an ID, which is the KV namespace ID.
[1:03] I'm just going to take this, I'm going to copy it, and in wrangler.toml, I'm just going to paste that in here. I'll also just clean up the spacing a little bit. You can see, I now have kv_namespaces equals an array with my_first_kv, as well as the KV namespace ID.
[1:21] That's all we need to do to add KV namespaces to our Workers Project. Any time that we publish this project, the KV namespaces and bindings associated to it will be updated, and we'll be able to make use of this KV namespace directly inside of our code.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!