Installation

Requirements

  • Node.js 22 for contributing to this repository
  • npm
  • A Cloudflare Workers project
  • A GitHub classic personal access token with read:packages permission and access to the package

The published bundles target ES2020. Node.js 22 is the supported development version and matches continuous integration.

Install the published package

The package is distributed through GitHub Packages. Add the scope and environment-backed authentication to the consuming project's .npmrc:

@bayudwiyansatria:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_AUTH_TOKEN}

Set the token for your current shell, then install both libraries.

PowerShell:

$env:NPM_AUTH_TOKEN = 'your-token'
npm install @bayudwiyansatria/core @bayudwiyansatria/cloudflare

POSIX shells:

export NPM_AUTH_TOKEN='your-token'
npm install @bayudwiyansatria/core @bayudwiyansatria/cloudflare

Do not write a literal token into .npmrc or commit one. Repository and package visibility are independent, so the GitHub account associated with the token must have permission to download the package.

@bayudwiyansatria/core is a direct runtime dependency. It provides the capability interfaces implemented here and the configure() function used during application startup.

Peer dependencies

Package Required? Purpose
@cloudflare/workers-types yes Provides the binding types referenced by the declarations
hono only for ./middlewares Provides the runtime types and API used by the optional Hono middleware entry

Published entries

import { cloudflareDefaults, KVService } from '@bayudwiyansatria/cloudflare'
import { SecurityMiddleware } from '@bayudwiyansatria/cloudflare/middlewares'
Entry Contents Files under lib/
. Bindings, services, configuration, CloudflareEnv index.min.cjs, index.min.mjs, index.d.ts
./middlewares SecurityMiddleware, logToAnalytics middlewares.min.cjs, middlewares.min.mjs, middlewares.d.ts

Source maps are generated for the JavaScript bundles but excluded from the package archive.

Module resolution

The ./middlewares subpath is declared in package.json#exports. For a Worker bundled by Wrangler, use a modern TypeScript resolution mode:

{
  "compilerOptions": {
    "moduleResolution": "Bundler"
  }
}

typesVersions also maps the middleware declarations for consumers using classic TypeScript resolution.

Install for development

git clone https://github.com/bayudwiyansatria/nodejs-cloudflare.git
cd nodejs-cloudflare

Set NPM_AUTH_TOKEN as shown above, then run:

npm install
npm test
npm run build

See Local Development for the complete contributor workflow.

Next

  • Quick Start — configure the library, use a capability, and wire bindings
  • Bindings — all supported bindings and their behavior

results matching ""

    No results matching ""