Skip to content

Local development

You can use Wrangler to develop and test Workers that use Hyperdrive:

  • wrangler dev with localConnectionString: Runs your Worker locally and connects directly to a database without Hyperdrive.
  • wrangler dev with remote: true on the binding: Runs your Worker locally and connects through your deployed Hyperdrive configuration.
  • wrangler dev --remote: Runs your Worker on Cloudflare and uses your deployed Hyperdrive configuration.

Use wrangler dev

To connect directly to a database without using your deployed Hyperdrive configuration, set localConnectionString and omit remote: true.

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=require or mysql://user:password@remote-host.example.com:3306/database?sslMode=required). You must specify the SSL/TLS mode if required.

Configure with environment variable

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 dev

The 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 dev

Configure in Wrangler configuration file

Alternatively, you can set localConnectionString in your Wrangler configuration file:

{
	"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.

Use wrangler dev with a remote binding

Use Wrangler 4.152.0 or later. Set remote: true on the Hyperdrive binding in your Wrangler configuration, then run wrangler dev:

{
	"hyperdrive": [
		{
			"binding": "HYPERDRIVE",
			"id": "your-hyperdrive-id",
			"remote": true,
		},
	],
}
[[hyperdrive]]
binding = "HYPERDRIVE"
id = "your-hyperdrive-id"
remote = true

With a remote binding, your Worker runs locally, but queries use the connection pooling and caching settings from your deployed Hyperdrive configuration. Use a test configuration to avoid writing to your production database.

Use wrangler dev --remote

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 --remote

Refer to the wrangler dev documentation to learn more about how to configure a local development session.

Was this helpful?