Gathering detailed insights and metrics for pg-cloudflare
Gathering detailed insights and metrics for pg-cloudflare
Gathering detailed insights and metrics for pg-cloudflare
Gathering detailed insights and metrics for pg-cloudflare
@neondatabase/serverless
node-postgres for serverless environments from neon.tech
unconventional-pg-queries
A lightweight postgres query builder
pg-compat
Patch to make pg work with both Node.js and Cloudflare.
@jawj/tmp-cfworker-pg
node-postgres via a WebSocket TCP proxy for Cloudflare Workers
npm install pg-cloudflare
Typescript
Module System
Node Version
NPM Version
JavaScript (79%)
TypeScript (19.89%)
Dockerfile (0.56%)
Makefile (0.55%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
12,780 Stars
2,827 Commits
1,275 Forks
182 Watchers
57 Branches
333 Contributors
Updated on Jul 13, 2025
Latest Version
1.2.7
Package Id
pg-cloudflare@1.2.7
Unpacked Size
22.55 kB
Size
6.68 kB
File Count
13
NPM Version
lerna/3.22.1/node@v20.10.0+arm64 (darwin)
Node Version
20.10.0
Published on
Jun 27, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
pg-cloudflare
makes it easier to take an existing package that relies on tls
and net
, and make it work in environments where only connect()
is supported, such as Cloudflare Workers.
pg-cloudflare
wraps connect()
, the TCP Socket API proposed within WinterCG, and implemented in Cloudflare Workers, and exposes an interface with methods similar to what the net
and tls
modules in Node.js expose. (ex: net.connect(path[, options][, callback])
). This minimizes the number of changes needed in order to make an existing package work across JavaScript runtimes.
npm i --save-dev pg-cloudflare
The package uses conditional exports to support bundlers that don't know about
cloudflare:sockets
, so the consumer code by default imports an empty file. To
enable the package, resolve to the cloudflare
condition in your bundler's
config. For example:
webpack.config.js
1export default { 2 ..., 3 resolve: { conditionNames: [..., "workerd"] }, 4 plugins: [ 5 // ignore cloudflare:sockets imports 6 new webpack.IgnorePlugin({ 7 resourceRegExp: /^cloudflare:sockets$/, 8 }), 9 ], 10}
vite.config.js
[!NOTE] If you are using the Cloudflare Vite plugin then the following configuration is not necessary.
1export default defineConfig({ 2 ..., 3 resolve: { 4 conditions: [..., "workerd"], 5 }, 6 build: { 7 ..., 8 // don't try to bundle cloudflare:sockets 9 rollupOptions: { 10 external: [..., 'cloudflare:sockets'], 11 }, 12 }, 13})
rollup.config.js
1export default defineConfig({ 2 ..., 3 plugins: [..., nodeResolve({ exportConditions: [..., 'workerd'] })], 4 // don't try to bundle cloudflare:sockets 5 external: [..., 'cloudflare:sockets'], 6})
esbuild.config.js
1await esbuild.build({ 2 ..., 3 conditions: [..., 'workerd'], 4})
The concrete examples can be found in packages/pg-bundler-test
.
As implemented in pg
here, a typical use case might look as follows, where in a Node.js environment the net
module is used, while in a non-Node.js environment, where net
is unavailable, pg-cloudflare
is used instead, providing an equivalent interface:
1module.exports.getStream = function getStream(ssl = false) { 2 const net = require('net') 3 if (typeof net.Socket === 'function') { 4 return net.Socket() 5 } 6 const { CloudflareSocket } = require('pg-cloudflare') 7 return new CloudflareSocket(ssl) 8}
If you're looking for a way to rely on connect()
as the interface you use to interact with raw sockets, but need this interface to be available in a Node.js environment, @arrowood.dev/socket
provides a Node.js implementation of the Socket API.
The MIT License (MIT)
Copyright (c) 2023 Brian M. Carlson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
30 commit(s) and 18 issue activity found in the last 90 days -- score normalized to 10
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 15/26 approved changesets -- score normalized to 5
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
44 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More