npm.io
1.1.1 • Published 5 years ago

cloudflare-kv-storage-rest

Licence
MIT
Version
1.1.1
Deps
2
Size
7 kB
Vulns
0
Weekly
0
Stars
17

cloudflare-kv-storage-rest

Tiny javascript and node wrapper for the cloudflare kv-storage rest-api.

There are a few api-wrappers available on github but so far I haven't found any that supports the new metadata functionality.

The idea with library is to create a wrapper around the the rest api that works exactly as the runtime API (https://developers.cloudflare.com/workers/reference/apis/kv)

Usage in browser

Create an instance of Kv-Storage. The instance will expose the same api as the variable in the runtime API.

Usage in nodejs

To use this is nodejs you can add node-fetch and form-data to the global context:

global.fetch = require('node-fetch');
global.FormData = require('form-data');

Another options is to pass the fetch and form-data shims to the constructor

const fetch = require('node-fetch');
const FormData = require('form-data');

const kvStorage = new KvStorage({
    namespace: 'namespace',
    accountId: 'accountId',
    fetch,
    FormData,
});