Skip to main content

Getting started

cf-common is a set of typed helpers for Cloudflare Workers bindings. You install it once and import only the modules you need — each is a separate subpath export, so your Worker bundle stays small.

Install

pnpm add @rtorcato/cf-common
npm install @rtorcato/cf-common

Import from subpaths

Always import from a service subpath — never from the package root:

// ✅ pulls in only the KV helper
import { kv } from '@rtorcato/cf-common/kv'

// ❌ the root entry is intentionally empty
import { kv } from '@rtorcato/cf-common'

Type your environment

Cloudflare passes bindings on the env argument. Declare them once so every helper is typed against your real bindings:

interface Env {
CACHE: KVNamespace
BUCKET: R2Bucket
DB: D1Database
}

A first Worker

import { getBinding } from '@rtorcato/cf-common/env'
import { kv } from '@rtorcato/cf-common/kv'

export default {
async fetch(req: Request, env: Env): Promise<Response> {
const store = kv(getBinding(env, 'CACHE'))
const user = await store.getJSON<{ id: number }>('u:42')
return Response.json(user ?? { id: 42 })
},
}
note

The module APIs shown here land incrementally — see the milestones for which modules are published. This page updates as each one ships.

Next steps

  • Browse the milestones to see what's available and what's coming.
  • Follow issues for per-module progress.