What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
A dynamic SvelteKit app on Cloudflare uses @sveltejs/adapter-cloudflare. For data, you have two documented routes. D1 is Cloudflare’s own database, reached through a binding. PostgreSQL is reached through Hyperdrive, and its drivers need Node.js compatibility turned on. Most deployment problems come from mismatched build directories, binding names, and runtime flags, not from SvelteKit itself.
One decision comes before any of that. Cloudflare now recommends Workers for new projects, so check whether Pages is the right target before you commit to it.
As an Amazon Associate I earn from qualifying purchases.
Pages or Workers: decide first
Cloudflare’s Pages framework guides index (last updated 2026-08-21) says Workers supports most Pages use cases, has a broader feature set, and is Cloudflare’s primary platform for applications. It recommends Workers for new projects. Pages is not described as discontinued, and the SvelteKit-on-Pages guide is still current. The rest of this article follows that Pages route.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →- Existing Pages project: the steps below apply directly.
- Starting fresh: read Cloudflare’s Workers guidance for SvelteKit before you pick Pages. The adapter,
platform.envbindings, D1 and Hyperdrive concepts carry over. The deployment configuration is the part that differs.
D1 or Postgres: what actually decides it
Cloudflare’s documentation supports a distinction in kind, not a ranking. It does not give a latency, price, SQL feature-parity or migration comparison. Don’t pick on claims about speed or cost that you can’t trace to a source.
#1 Best Overall
| Question | D1 | PostgreSQL via Hyperdrive |
|---|---|---|
| What is it? | Cloudflare’s native serverless database, accessed through a binding | An existing PostgreSQL database, reached through a Hyperdrive binding |
| Choose it when… | You’re building new and the native binding model suits the app | You need PostgreSQL compatibility or already have a Postgres database |
| Runtime requirement | Binding declared and exposed on platform.env |
Node.js compatibility (nodejs_compat) for drivers such as Postgres.js |
| Code access | platform.env.DB (name is yours to choose) |
platform.env.HYPERDRIVE (name is yours to choose) |
Sources: Cloudflare’s D1 and SvelteKit example, Pages bindings and Hyperdrive PostgreSQL guide.
Set up the project and adapter
Cloudflare’s SvelteKit guide for Pages offers two starting points.
New project with create-cloudflare
npm create cloudflare@latest -- my-svelte-app --framework=svelte --platform=pages
The C3 tool installs Wrangler and the adapter for you.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteExisting SvelteKit project
Install @sveltejs/adapter-cloudflare and set it as the adapter in svelte.config.js. Commit the change before you deploy. Pages builds from your repository, so an uncommitted adapter switch won’t reach the build.
Rank #2
Get the build settings right
For dashboard or Git-based deployments, Cloudflare’s build configuration page lists the SvelteKit preset as:
- Build command:
npm run build - Build output directory:
.svelte-kit/cloudflare
Pages can rebuild on each pushed commit and create preview deployments for pull requests.
The output directory depends on the adapter. If the project uses adapter-static, which produces client-side assets with no server-side rendering, the output directory is build, and you must set that in Pages. A database-backed app needs server code, so it should be on the Cloudflare adapter. If a deploy “succeeds” but serves nothing useful, check this setting first, and don’t copy a directory from another framework’s tutorial.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Connecting D1
Cloudflare’s D1 guide uses a SvelteKit server endpoint with D1 bound to the Pages Function. Inside a SvelteKit handler, the binding is on the platform argument, typically platform.env.DB.
Rank #3
Declare the binding type
For TypeScript, declare the binding as D1Database on App.Platform in src/app.d.ts:
declare global {
namespace App {
interface Platform {
env: {
DB: D1Database;
};
}
}
}
export {};
Query it from an endpoint
Cloudflare’s example uses a prepared statement and returns JSON. The shape is as follows (the table and column names are placeholders, not from Cloudflare’s example):
// src/routes/api/posts/+server.ts
import { json } from '@sveltejs/kit';
export async function GET({ platform }) {
const { results } = await platform.env.DB
.prepare('SELECT id, title FROM posts WHERE published = ?')
.bind(1)
.all();
return json(results);
}
Run it locally
Pass the binding to Wrangler with --d1 BINDING_NAME=DATABASE_ID. Cloudflare’s Pages bindings page gives the form as wrangler pages dev <OUTPUT_DIR> --d1 BINDING_NAME=DATABASE_ID, while the D1 SvelteKit example shows it with wrangler dev. Use the command from the page that matches your project’s setup. The binding name must match your code. Wrangler persists local data to local storage by default. That means rows you create while developing are not in your production database, and the reverse also holds.
Connecting PostgreSQL through Hyperdrive
Cloudflare documents Hyperdrive as the way for Workers and Pages Functions to reach an existing database, PostgreSQL included. Pages supports a Hyperdrive binding in its Wrangler configuration. Cloudflare’s PostgreSQL example uses a binding named HYPERDRIVE and the Postgres.js client.
The Node.js compatibility requirement
This is the gotcha that costs the most time. Cloudflare states that PostgreSQL drivers such as Postgres.js depend on Node.js APIs. Pages Functions that use Hyperdrive must therefore be deployed with Node.js compatibility. The documented configuration has the nodejs_compat compatibility flag and a compatibility date. Adding a Hyperdrive binding alone doesn’t make a Node-oriented driver work.
A Wrangler configuration has this shape. The IDs are placeholders, and you should copy the exact fields from Cloudflare’s current pages for your Wrangler version:
compatibility_date = "YYYY-MM-DD"
compatibility_flags = ["nodejs_compat"]
[[hyperdrive]]
binding = "HYPERDRIVE"
id = "<YOUR_HYPERDRIVE_CONFIG_ID>"
Using it in a handler
import postgres from 'postgres';
export async function GET({ platform }) {
const sql = postgres(platform.env.HYPERDRIVE.connectionString);
const rows = await sql`SELECT id, title FROM posts LIMIT 10`;
return new Response(JSON.stringify(rows), {
headers: { 'content-type': 'application/json' }
});
}
Declare HYPERDRIVE in App.Platform in the same way as DB above. Then test on the actual deployed runtime, not only locally. The flags and compatibility date that make a driver load are exactly the things that can differ between your dev server and a Pages deployment.
The documentation supports connecting to an existing PostgreSQL database in general. It doesn’t vouch for any particular managed-Postgres provider, so check your provider’s own notes on connecting from Cloudflare.
Best Value
Gotchas that apply to either database
Root /functions files are ignored
SvelteKit on Pages compiles to a single _worker.js. Handlers in a root /functions directory, the usual Pages Functions convention, are not included. Write your logic as SvelteKit endpoints (+server.ts) or in +page.server.ts load functions and actions.
Binding names must agree everywhere
The name in your Wrangler configuration, the --d1 flag and your code (platform.env.DB) must be identical, as must the TypeScript declaration. A mismatch usually shows up as platform.env.X being undefined at request time.
Dashboard binding changes need a redeploy
If you add or change a binding in the Pages dashboard instead of the configuration file, it only takes effect after you redeploy, per Cloudflare’s bindings documentation. Adding a binding and refreshing the live site won’t show it.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteLocal data is not production data
A table that works on your machine and is missing in production usually means the schema was applied only to the local database. Apply schema changes to the remote database as a separate step.
Where this leaves you
Use the Cloudflare adapter and .svelte-kit/cloudflare for a database-backed Pages deployment. Choose D1 if you want the native binding model, or Postgres through Hyperdrive if you need PostgreSQL or already run it, and then enable nodejs_compat. For a brand-new project, compare it against Workers first, since that is where Cloudflare is steering new applications.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




