INTEGRITY Cloudflare Docs

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:

Use wrangler dev

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:

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

When you run wrangler dev --remote, your Worker runs in Cloudflare's network and uses your deployed Hyperdrive configuration. This means:

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.