Seeding KV for usage with wrangler pages dev

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()

@Walshy I know. My question is: how can I seed those local namespaces when in development?

@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:
<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:

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