Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Kikobeats/cloudflare-workers-kv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@kikobeats/cloudflare-workers-kv

Last version Coverage Status NPM Status

Node.js library to interact with CloudFlare Workers KV.

Deprecation note: this library uses CloudFlare REST API that is slow. You should to use runtime API to interact the most optimal way.

CloudFlare Workers KV is faster <key, value> storage that runs on top of CloudFlare Network to offer a geo-distributed service almost free or reasonable cheaper.

Use it in combination with CloudFlare Workers or AWS Lambda to have a truly serverless database access, where the value will be serve from the nearest edge node, being the lowest response latency possible.

Install

$ npm install @kikobeats/cloudflare-workers-kv --save

Usage

The library is a convenient way to interact with CloudFlare Workers KV via usinng CloudFlare Workers KV API.

const cloudFlareWorkersKV = require('@kikobeats/cloudflare-workers-kv')
const ms = require('ms')

const store = cloudFlareWorkersKV({
  accountId: '<Cloudflare-Account-Id>',
  key: '<Cloudflare-API-Key>',
  namespaceId: '<Cloudflare-Workers-KV-Namespace-Id>'
})

async function examples () {
  // get a value
  await store.get('foo')

  // set a value forever
  await store.set('foo', 'bar')

  // set a value associating with a time-to-live associated
  await store.set('foo', 'bar', ms('5m'))

  // delete a value
  await store.delete('foo')
}

Authentication

At CloudFlare dashboard, enter to Your Profile > API Token > Create Token.

Then use CloudFlare Workers template and ensure at least the permission Workers KV Storage is present.

The API token provided should be provided as key.

License

@kikobeats/cloudflare-workers-kv © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats