Local development
Hyperdrive can be used when developing and testing your Workers locally. Wrangler, the command-line interface for Workers, provides two options for local development:
wrangler dev(default): Runs your Worker code locally on your machine. You configure alocalConnectionStringto connect directly to a database (either local or remote). Hyperdrive query caching does not take effect in this mode.wrangler dev --remote: Runs your Worker on Cloudflare's using your deployed Hyperdrive configuration. This is useful for testing with Hyperdrive's connection pooling and query caching enabled.
By default, wrangler dev runs your Worker code locally on your machine. To connect to a database during local development, configure a localConnectionString that points directly to your database.
The localConnectionString works with both local and remote databases:
- Local databases: Connect to a database instance running on your machine (for example,
postgres://user:password@localhost:5432/database) - Remote databases: Connect directly to remote databases over TLS (for example,
postgres://user:password@remote-host.example.com:5432/database?sslmode=requireormysql://user:password@remote-host.example.com:3306/database?sslMode=required). You must specify the SSL/TLS mode if required.
The recommended approach is to use an environment variable to avoid committing credentials to source control:
# Your configured Hyperdrive binding is "HYPERDRIVE"export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:password@your-database-host:5432/database"npx wrangler devThe environment variable format is CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>, where <BINDING_NAME> is the name of the binding assigned to your Hyperdrive in your Wrangler configuration file.
To unset an environment variable: unset CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>
For example, to set the connection string for a local database:
export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:password@localhost:5432/databasename"npx wrangler devAlternatively, you can set localConnectionString in your Wrangler configuration file:
{ "$schema": "./node_modules/wrangler/config-schema.json", "hyperdrive": [ { "binding": "HYPERDRIVE", "id": "c020574a-5623-407b-be0c-cd192bab9545", "localConnectionString": "postgres://user:password@localhost:5432/databasename" } ]}[[hyperdrive]]binding = "HYPERDRIVE"id = "c020574a-5623-407b-be0c-cd192bab9545"localConnectionString = "postgres://user:password@localhost:5432/databasename"If both an environment variable and localConnectionString in the Wrangler configuration file are set, the environment variable takes precedence.
When you run wrangler dev --remote, your Worker runs in Cloudflare's network and uses your deployed Hyperdrive configuration. This means:
- Your Worker code executes in Cloudflare's production environment, not locally
- Hyperdrive's connection pooling and query caching are active
- You connect to the database configured in your Hyperdrive configuration (created with
wrangler hyperdrive create) - Changes made during the session interact with remote resources
This mode is useful for testing how your Worker behaves with Hyperdrive's features enabled before deploying.
Configure your Hyperdrive binding in wrangler.jsonc:
{ "hyperdrive": [ { "binding": "HYPERDRIVE", "id": "your-hyperdrive-id", }, ],}[[hyperdrive]]binding = "HYPERDRIVE"id = "your-hyperdrive-id"To start a remote development session:
npx wrangler dev --remoteRefer to the wrangler dev documentation to learn more about how to configure a local development session.
- Use
wrangler devto run your Worker and Hyperdrive locally and debug issues before deploying. - Learn how Hyperdrive works.
- Understand how to configure query caching in Hyperdrive.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-