You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update Postgres tutorial to use node-postgres (#23353)
* Update Postgres tutorial to use node-postgres
* Update src/content/docs/workers/tutorials/postgres/index.mdx
---------
Co-authored-by: Jun Lee <[email protected]>
Copy file name to clipboardExpand all lines: src/content/docs/workers/tutorials/postgres/index.mdx
+94-65Lines changed: 94 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
updated: 2024-08-23
2
+
updated: 2025-07-01
3
3
difficulty: Beginner
4
4
pcx_content_type: tutorial
5
5
title: Connect to a PostgreSQL database with Cloudflare Workers
@@ -62,11 +62,17 @@ cd postgres-tutorial
62
62
63
63
## 2. Add the PostgreSQL connection library
64
64
65
-
To connect to a PostgreSQL database, you will need the `postgres` library. In your Worker application directory, run the following command to install the library:
65
+
To connect to a PostgreSQL database, you will need the `pg` library. In your Worker application directory, run the following command to install the library:
66
66
67
-
<PackageManagerspkg="postgres" />
67
+
<PackageManagerspkg="pg" />
68
68
69
-
Make sure you are using `postgres` (`Postgres.js`) version `3.4.4` or higher. `Postgres.js` is compatible with both Pages and Workers.
69
+
Next, install the TypeScript types for the `pg` library to enable type checking and autocompletion in your TypeScript code:
70
+
71
+
<PackageManagerspkg="@types/pg"dev />
72
+
73
+
:::note
74
+
Make sure you are using `pg` (`node-postgres`) version `8.16.3` or higher.
75
+
:::
70
76
71
77
## 3. Configure the connection to the PostgreSQL database
72
78
@@ -115,7 +121,7 @@ Configure each database parameter as an [environment variable](/workers/configur
115
121
DB_USERNAME = "postgres"
116
122
# Set your password by creating a secret so it is not stored as plain text
0 commit comments