I’m using the --kv
option of the wrangler pages dev
command in order to bind the pages server with KV namespaces. Those are initialized empty. How can I seed them?
Local dev cannot use remote resources, so this is local KV. You write the same way as usual, KV.put()
@tavoyne … got help on this on discord from @zszszsz.
The solution:
On the root directory of your project … i.e. where the functions directory is, create a file in a directory:
.wrangler/state/kv/<bind-name>/<key>
<bind-name> is your KV namespace
<key> is a file with the name of your key.
for me bind-name is TEST, key is BUG_TEST. So my file is:
.wrangler/state/kv/TEST/BUG_TEST
Inside the file place the value
Then when you start your wrangler use --persist. For me, using pages, the command is:
npx wrangler pages dev --kv=TEST --persist -- npm start
Also, if you are using git don’t forget to add .wrangler to .gitignore