---
title: "Cloudflare Workers + D1"
description: "Deploy Calends to your own Cloudflare account — one-click or from the command line — with the D1 database, the cron trigger and optional email reminders."
lang: "en"
version: "1.84.0"
url: "https://docs.calends.date/en/self-host/cloudflare/"
markdown_url: "https://docs.calends.date/en/self-host/cloudflare.md"
section: "Self-hosting"
llms_index: "https://docs.calends.date/llms.txt"
llms_full: "https://docs.calends.date/llms-full.txt"
agents_guide: "https://calends.date/AGENTS.md"
---

# Cloudflare Workers + D1

> Deploy Calends to your own Cloudflare account — one-click or from the command line — with the D1 database, the cron trigger and optional email reminders.

- Canonical page: https://docs.calends.date/en/self-host/cloudflare/
- Markdown source: https://docs.calends.date/en/self-host/cloudflare.md
- Calends version: v1.84.0

Deploy Calends to your Cloudflare account with D1, scheduled jobs and optional email reminders.

Calends is a Cloudflare Worker: the front end is served as the Worker's static assets, data lives in D1 (SQLite), and reminders and exchange rates run on a cron trigger. Usage and cost depend on your Cloudflare account’s current plan and quotas.

## Requirements

- A Cloudflare account;
- for command-line deploys, Node.js 24 and git.

## One-click deploy

Open [Deploy to Cloudflare](https://deploy.workers.cloudflare.com/?url=https://github.com/imetn/calends) and follow the steps to copy the repository into your GitHub account and deploy it.

Then, in the Cloudflare dashboard, open the Worker's **Settings → Variables and Secrets** and add a secret named `SETUP_TOKEN` with a long random value. Without it you can't set a password.

## Command-line deploy

1. Clone and install:

   ```bash
   git clone https://github.com/imetn/calends && cd calends
   npm ci
   ```

2. Sign in to Cloudflare and check that `npx wrangler whoami` shows your account:

   ```bash
   npx wrangler login
   ```

3. Set the setup token:

   ```bash
   npx wrangler secret put SETUP_TOKEN
   ```

   `openssl rand -base64 24` is one way to generate a random value.

4. Deploy:

   ```bash
   npm run deploy
   ```

5. Open `https://calends.<your-subdomain>.workers.dev`, enter the setup token and choose your password.

`npm run deploy` does the following:

1. generates the migration and translation files, type-checks, and builds the front end with Vite;
2. deploys the Worker with `wrangler deploy`. On the first deploy, a D1 database named `calends` is created automatically — no `database_id` to fill in;
3. applies all migrations to the remote database.

The Worker also checks for and applies missing migrations the first time each instance handles a request, so one-click deployments work too.

## wrangler.jsonc

The `wrangler.jsonc` in the repository is ready to go:

| Setting | What it does |
| --- | --- |
| `assets` | Front-end assets. `/api/*`, `/cal/*` and `/mcp` go to the Worker first; other paths fall back to the single-page app. |
| `d1_databases` | Binding `DB`, database `calends`. |
| `triggers.crons` | `*/15 * * * *`: checks reminders and retries every 15 minutes. FX maintenance runs at UTC hour boundaries and refreshes rates older than 20 hours. |
| `observability` | Workers logs on, so reminder results and migrations show up in the dashboard. |

## Email reminders

Email reminders use [Cloudflare Email Sending](https://developers.cloudflare.com/email-routing/email-workers/send-email-workers/). Skip this section if you don't need email; no other channel needs server-side configuration.

1. Enable email sending for your domain in Cloudflare and verify a sender address, such as `calends@example.com`.
2. In `wrangler.jsonc`, uncomment and edit these two entries:

   ```jsonc
   "send_email": [{ "name": "EMAIL", "allowed_sender_addresses": ["calends@example.com"] }],
   "vars": { "SITE_URL": "https://calends.example.com", "MAIL_FROM": "calends@example.com", "MAIL_FROM_NAME": "Calends" },
   ```

3. Deploy again: `npm run deploy`.
4. Under **Settings → Notification channels**, add an email channel with your address and click **Test**.

> **NOTE**: `MAIL_FROM_NAME` is optional and defaults to the app name in your interface language. `SITE_URL` is optional too; it sets the address used in reminder and calendar links. See [Configuration](https://docs.calends.date/en/self-host/config.md).

## Custom domain

See [Custom domain and HTTPS](https://docs.calends.date/en/self-host/custom-domain.md).

## Cost

Usage includes Workers requests, D1 reads, writes and storage, Cron, optional R2 storage/operations, and email sending. Check actual usage and current quotas in your Cloudflare dashboard. The built-in assistant uses your selected provider, billed separately from Cloudflare.

## File storage

File uploads require a private R2 bucket bound as `FILES`; without it uploads are disabled and other ledger features continue to work. Create it with `npx wrangler r2 bucket create calends-files`, add `"r2_buckets": [{ "binding": "FILES", "bucket_name": "calends-files" }]` to your Wrangler configuration, keep public access disabled, and redeploy. `FILES_LIMIT_MB` sets total capacity in MB (default 300); each file is limited to 10 MB.

---

## Related Pages & Global AI Discovery

To explore broader context beyond this page, fetch any of the Markdown or plain-text resources below directly:

### Same Section (Self-hosting)
- [Cloudflare Workers + D1](https://docs.calends.date/en/self-host/cloudflare.md) *(current)*
- [Docker](https://docs.calends.date/en/self-host/docker.md)
- [Configuration](https://docs.calends.date/en/self-host/config.md)
- [Custom domain and HTTPS](https://docs.calends.date/en/self-host/custom-domain.md)
- [Upgrading](https://docs.calends.date/en/self-host/upgrade.md)
- [Local development](https://docs.calends.date/en/self-host/development.md)
- [Translating](https://docs.calends.date/en/self-host/translate.md)

### Reading Order
- Previous: [Privacy](https://docs.calends.date/en/data/privacy.md)
- Next: [Docker](https://docs.calends.date/en/self-host/docker.md)

### Global Calends Resources
- Read-only Docs MCP Server (zero auth Streamable HTTP): https://docs.calends.date/mcp
- Complete Docs Index (all 37 topics with `.md` links): https://docs.calends.date/llms.txt
- Complete English Docs Bundle (single file): https://docs.calends.date/llms-full.txt
- Complete Simplified Chinese Docs Bundle: https://docs.calends.date/llms-zh.txt
- Docs AI Agent Guide: https://docs.calends.date/AGENTS.md
- Product Website Overview (Markdown): https://calends.date/en/index.md
- Product LLMs Index & Full Reference: https://calends.date/llms.txt | https://calends.date/llms-full.txt
- Deployment & MCP Agent Guide (AGENTS.md): https://calends.date/AGENTS.md
- FAQ & Calends vs Wallos Comparison (Markdown): https://calends.date/en/faq.md | https://calends.date/en/compare.md
- Complete Changelog (Markdown): https://calends.date/en/releases.md
