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.
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
| File | Contains | Use For |
|---|---|---|
SKILL.md | Entry point: scope, routing table, and workflow. | Start here. |
docs/connect-to-a-postgresql-database-with-cloudflare-workers-workflow-guide.md | A 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.text | A 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.text | The 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.text | The 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.text | A 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.text | A 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.text | A 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.text | The 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.text | The 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.text | The 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.text | The 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.text | The 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.text | The 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.text | The 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.text | The 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.text | A 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.text | A 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.text | Instructions 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | The 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.text | A 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.text | A 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.text | A 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.text | A 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.text | A 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.text | The 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.text | A 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
- Open the most relevant file under
docs/for the exact documented workflow and wording. - Open
schemas/files for exact structured contracts. - Open
examples/files for concrete requests, commands, snippets, and manifests. - Do not add behavior or configuration that is not present in the attached source files.
Canonical source: https://developers.cloudflare.com/workers/tutorials/postgres
