Prompt Buddy logoPrompt Buddy

cloudflare · Cloudflare Workers Docs

Connect to a PostgreSQL database with Cloudflare Workers

A step-by-step tutorial for creating a Cloudflare Worker, enabling Node.js compatibility, and establishing a connection to a PostgreSQL database using TCP Sockets and Hyperdrive.

Import to Prompt Buddy

Derived skill

Files assembled from official documentation

Viewing SKILL.md

Connect to a PostgreSQL database with Cloudflare Workers

A step-by-step tutorial for creating a Cloudflare Worker, enabling Node.js compatibility, and establishing a connection to a PostgreSQL database using TCP Sockets and Hyperdrive.

When To Use

Use when you need to implement a workflow to connect a Cloudflare Worker to a PostgreSQL database using Hyperdrive and TCP Sockets.

Reference Files

FileContainsUse For
SKILL.mdEntry point: scope, routing table, and workflow.Start here.
docs/connect-to-a-postgresql-database-with-cloudflare-workers-workflow-guide.mdA tutorial guide for creating a Cloudflare Workers application that connects to a PostgreSQL database using TCP Sockets and Hyperdrive.Questions about a tutorial guide for creating a Cloudflare Workers application that connects to a PostgreSQL database using TCP Socke...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work.textA step-by-step tutorial guide for connecting a Cloudflare Worker to a PostgreSQL database using the provided npm starter template.Exact payloads, commands, or snippets shown in A step-by-step tutorial guide for connecting a Cloudflare Worker to a PostgreSQL database using the provided npm star...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-2.textThe shell commands required to initialize the Cloudflare Workers PostgreSQL tutorial project using yarn.Exact payloads, commands, or snippets shown in The shell commands required to initialize the Cloudflare Workers PostgreSQL tutorial project using yarn.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-3.textThe shell commands required to initialize a new Cloudflare Workers project using the postgres-tutorial template via pnpm.Exact payloads, commands, or snippets shown in The shell commands required to initialize a new Cloudflare Workers project using the postgres-tutorial template via p...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-4.textA sequence of shell commands to initialize the project directory and navigate to the tutorial folder.Exact payloads, commands, or snippets shown in A sequence of shell commands to initialize the project directory and navigate to the tutorial folder.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-5.textA wrangler.toml configuration file demonstrating the compatibility flags and settings required to connect a Cloudflare Worker to a PostgreSQL database.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file demonstrating the compatibility flags and settings required to connect a Cloudflar...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-6.textA wrangler.toml configuration file specifying nodejs_compat compatibility flags and a compatibility date for connecting Cloudflare Workers to a PostgreSQL database.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file specifying nodejscompat compatibility flags and a compatibility date for connectin...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-7.textThe shell command to install the pg library required to connect Cloudflare Workers to a PostgreSQL database.Exact payloads, commands, or snippets shown in The shell command to install the pg library required to connect Cloudflare Workers to a PostgreSQL database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-8.textThe shell commands required to install the pg library for connecting Cloudflare Workers to a PostgreSQL database.Exact payloads, commands, or snippets shown in The shell commands required to install the pg library for connecting Cloudflare Workers to a PostgreSQL database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-9.textThe shell command to install the pg package using pnpm for connecting Cloudflare Workers to a PostgreSQL database.Exact payloads, commands, or snippets shown in The shell command to install the pg package using pnpm for connecting Cloudflare Workers to a PostgreSQL database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-10.textThe command to install the pg package using the Bun package manager for connecting Cloudflare Workers to a PostgreSQL database.Exact payloads, commands, or snippets shown in The command to install the pg package using the Bun package manager for connecting Cloudflare Workers to a PostgreSQL...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-11.textThe npm command to install the pg type definitions required for connecting Cloudflare Workers to a PostgreSQL database.Exact payloads, commands, or snippets shown in The npm command to install the pg type definitions required for connecting Cloudflare Workers to a PostgreSQL database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-12.textThe shell commands required to install the necessary type definitions for the pg library in a Cloudflare Workers project.Exact payloads, commands, or snippets shown in The shell commands required to install the necessary type definitions for the pg library in a Cloudflare Workers proj...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-13.textThe shell commands required to install the pg type definitions using pnpm for a Cloudflare Workers PostgreSQL connection.Exact payloads, commands, or snippets shown in The shell commands required to install the pg type definitions using pnpm for a Cloudflare Workers PostgreSQL connect...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-14.textThe shell commands required to install the pg type definitions using bun for a Cloudflare Workers PostgreSQL connection.Exact payloads, commands, or snippets shown in The shell commands required to install the pg type definitions using bun for a Cloudflare Workers PostgreSQL connection.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-15.textA text representation of the PostgreSQL connection string format required to connect a Cloudflare Worker to a database.Exact payloads, commands, or snippets shown in A text representation of the PostgreSQL connection string format required to connect a Cloudflare Worker to a database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-16.textA text instruction for setting the DB_URL environment variable using the wrangler secret command.Exact payloads, commands, or snippets shown in A text instruction for setting the DBURL environment variable using the wrangler secret command.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-17.textInstructions and commands for configuring the DB_URL secret using the Wrangler CLI to connect a Cloudflare Worker to a PostgreSQL database.Exact payloads, commands, or snippets shown in Instructions and commands for configuring the DBURL secret using the Wrangler CLI to connect a Cloudflare Worker to a...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-18.textA text snippet showing the format for the DB_URL environment variable used to connect a Cloudflare Worker to a PostgreSQL database.Exact payloads, commands, or snippets shown in A text snippet showing the format for the DBURL environment variable used to connect a Cloudflare Worker to a Postgre...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-19.textA text file containing the environment variable configuration required to connect a Cloudflare Worker to a PostgreSQL database.Exact payloads, commands, or snippets shown in A text file containing the environment variable configuration required to connect a Cloudflare Worker to a PostgreSQL...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-20.textA text file containing the database connection configuration variables including host, port, username, and database name for a Cloudflare Workers PostgreSQL integration.Exact payloads, commands, or snippets shown in A text file containing the database connection configuration variables including host, port, username, and database n...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-21.textA command-line instruction for setting the DB_PASSWORD secret using the Wrangler CLI to enable database connectivity in a Cloudflare Worker.Exact payloads, commands, or snippets shown in A command-line instruction for setting the DBPASSWORD secret using the Wrangler CLI to enable database connectivity i...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-22.textA command line interaction showing the successful upload of a DBPASSWORD secret using the Wrangler CLI.Exact payloads, commands, or snippets shown in A command line interaction showing the successful upload of a DBPASSWORD secret using the Wrangler CLI.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-23.textA JavaScript code example demonstrating how to import the pg client and establish a connection to a PostgreSQL database within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to import the pg client and establish a connection to a PostgreSQL databa...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-24.textA JavaScript code snippet demonstrating how to instantiate and connect to a PostgreSQL database using a connection string within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript code snippet demonstrating how to instantiate and connect to a PostgreSQL database using a connection st...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-25.textA JavaScript code snippet demonstrating how to instantiate and connect to a PostgreSQL database using a Client instance within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript code snippet demonstrating how to instantiate and connect to a PostgreSQL database using a Client instan...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-26.textA SQL command to create a products table with id, name, description, and price columns for a PostgreSQL database.Exact payloads, commands, or snippets shown in A SQL command to create a products table with id, name, description, and price columns for a PostgreSQL database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-27.textA JavaScript code example demonstrating how to instantiate a PostgreSQL client and execute queries within a Cloudflare Worker using a connection string.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to instantiate a PostgreSQL client and execute queries within a Cloudflar...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-28.textThe terminal command used to deploy a Cloudflare Worker configured to connect to a PostgreSQL database.Exact payloads, commands, or snippets shown in The terminal command used to deploy a Cloudflare Worker configured to connect to a PostgreSQL database.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-29.textA JavaScript code example demonstrating how to initialize and connect to a PostgreSQL database using the pg client within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to initialize and connect to a PostgreSQL database using the pg client wi...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-30.textA sample JSON object representing product data used to demonstrate a connection between Cloudflare Workers and a PostgreSQL database.Exact payloads, commands, or snippets shown in A sample JSON object representing product data used to demonstrate a connection between Cloudflare Workers and a Post...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-31.textA CLI command using wrangler to create a Hyperdrive configuration with a PostgreSQL connection string.Exact payloads, commands, or snippets shown in A CLI command using wrangler to create a Hyperdrive configuration with a PostgreSQL connection string.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-32.textA wrangler.toml configuration file demonstrating how to bind a Hyperdrive instance to a Cloudflare Worker for PostgreSQL connectivity.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file demonstrating how to bind a Hyperdrive instance to a Cloudflare Worker for Postgre...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-33.textA wrangler.toml configuration file demonstrating how to bind a Hyperdrive instance to a Cloudflare Worker for PostgreSQL connectivity.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file demonstrating how to bind a Hyperdrive instance to a Cloudflare Worker for Postgre...
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-34.textThe command used to generate TypeScript types for Cloudflare Workers using wrangler.Exact payloads, commands, or snippets shown in The command used to generate TypeScript types for Cloudflare Workers using wrangler.
examples/connect-to-a-postgresql-database-with-cloudflare-workers-cloudflare-work-35.textA JavaScript code example demonstrating how to connect a Cloudflare Worker to a PostgreSQL database using Hyperdrive via the connection string in the environment variables.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to connect a Cloudflare Worker to a PostgreSQL database using Hyperdrive...

What This Skill Covers

  • In this tutorial, you will learn how to create a Cloudflare Workers application and connect it to a PostgreSQL database using TCP Sockets and Hyperdrive. The...
  • Main sections: Tags, Prerequisites, 1\. Create a Worker application, Enable Node.js compatibility, 2\. Add the PostgreSQL connection library.

Workflow

  1. Open the most relevant file under docs/ for the exact documented workflow and wording.
  2. Open schemas/ files for exact structured contracts.
  3. Open examples/ files for concrete requests, commands, snippets, and manifests.
  4. Do not add behavior or configuration that is not present in the attached source files.

Canonical source: https://developers.cloudflare.com/workers/tutorials/postgres