Skip to content

Files

Latest commit

e684ff0 · Dec 14, 2024

History

History

with-hyperdrive

Getting started with Neon and Cloudflare Hyperdrive

Clone the repository

npx degit neondatabase/examples/with-hyperdrive ./with-hyperdrive

Get your Neon credentials

DATABASE_URL="postgresql://neondb_owner:[email protected]/neondb?sslmode=require"
  • user is the database user.
  • password is the database user’s password.
  • endpoint_hostname is the host with neon.tech as the TLD.
  • dbname is the name of the database. “neondb” is the default database created with each Neon project.
  • ?sslmode=require an optional query parameter that enforces the SSL mode while connecting to the Postgres instance for better security.

Important: To ensure the security of your data, never expose your Neon credentials to the browser.

Create a database configuration

To create a Hyperdrive configuration with the Wrangler CLI, open your terminal and run the following command:

npx wrangler hyperdrive create <NAME_OF_HYPERDRIVE_CONFIG> --connection-string="postgresql://neondb_owner:[email protected]/neondb?sslmode=require"

This command outputs a binding to be used in the wrangler.toml file:

#:schema node_modules/wrangler/config-schema.json
main = "src/index.ts"
compatibility_date = "2024-12-05"
compatibility_flags = ["nodejs_compat"]
# Pasted from the output of `wrangler hyperdrive create <NAME_OF_HYPERDRIVE_CONFIG> --connection-string=[...]` above.
[[hyperdrive]]
binding = "HYPERDRIVE"
id = "<ID OF THE CREATED HYPERDRIVE CONFIGURATION>"

Run the command below to install project dependencies:

npm install

Deploy the Cloudflare worker using the following command:

npm run deploy