{"id":18661,"library":"pg-gateway","title":"pg-gateway","description":"pg-gateway is a TypeScript library that implements the PostgreSQL wire protocol for the server side, enabling developers to build custom Postgres-compatible proxies, middleware, or gateways. The current version is 0.3.0-beta.4, indicating an early beta stage with potential breaking changes. It focuses on low-level protocol handling, differentiating from higher-level clients like node-postgres by giving direct control over the protocol flow. Releases are infrequent and experimental.","status":"active","version":"0.3.0-beta.4","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install pg-gateway","lang":"bash","label":"npm"},{"cmd":"yarn add pg-gateway","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-gateway","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Buffer is used for handling binary protocol data","package":"node:buffer","optional":false}],"imports":[{"note":"The package is ESM-first but may have a CommonJS fallback. Check package.json exports.","wrong":"const PgGateway = require('pg-gateway')","symbol":"default","correct":"import PgGateway from 'pg-gateway'"},{"note":"Named export for the library class.","wrong":"import PgGateway from 'pg-gateway'","symbol":"PgGateway","correct":"import { PgGateway } from 'pg-gateway'"},{"note":"Named export for backend message types, useful for parsing protocol messages.","wrong":"import BackendMessage from 'pg-gateway'","symbol":"BackendMessage","correct":"import { BackendMessage } from 'pg-gateway'"}],"quickstart":{"code":"import PgGateway from 'pg-gateway';\nimport net from 'node:net';\n\nconst gateway = new PgGateway();\n// Create a server that proxies to a real PostgreSQL backend\nnet.createServer((socket) => {\n  gateway.handleClient(socket, {\n    backend: { host: 'localhost', port: 5432, user: 'user', password: process.env.PGPASSWORD ?? '' }\n  });\n}).listen(5433, () => {\n  console.log('Gateway listening on 5433');\n});","lang":"typescript","description":"Creates a simple TCP server that uses pg-gateway to proxy client connections to a real PostgreSQL instance, demonstrating the primary use case."},"warnings":[{"fix":"Pin to a specific version and test upgrades carefully. Consult changelog if available.","message":"Beta version 0.3.0 may have breaking changes from earlier alphas. No stable release yet.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Do not import in client-side code; ensure bundler excludes it for browser bundles.","message":"The package is intended for server-side usage only; it does not work in browser environments due to reliance on Node.js net module.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Watch for updates and migration guides.","message":"No known deprecated APIs yet, but as a beta package, certain APIs may be removed later.","severity":"deprecated","affected_versions":">=0.3.0-beta.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `import PgGateway from 'pg-gateway'` in ESM, or `const PgGateway = require('pg-gateway').default` in CommonJS.","cause":"Importing the default export incorrectly when using CommonJS or mismatched module system.","error":"TypeError: PgGateway is not a constructor"},{"fix":"Install with `npm install pg-gateway` and verify the import path is correct.","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'pg-gateway'"},{"fix":"Use only in Node.js; exclude from browser bundles.","cause":"Attempting to use in a browser or non-Node environment.","error":"Error: The module 'pg-gateway' is not compatible with the 'node' platform"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}