Registry / database / pg-postgis-types

pg-postgis-types

JSON →
library3.0.0jsnpmunverified

Registers custom parsers for PostGIS geometry and geography types in node-postgres, converting binary WKB to objects with toGeoJSON(). v3.0.0 requires pg and pg-custom-types. Lightweight alternative to massive ORMs; relies on wkx by default but allows custom WKB parsers. Low release cadence, mostly maintenance.

npm install pg-postgis-types
INSTALL
IMPORT
SIG · PG-POSTGIS-TYPES
P
pg-postgis-types
databasejavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

postgis
import postgis from 'pg-postgis-types'
const postgis = require('pg-postgis-types')
ESM/CJS dual support; default export.
postgis
import { postgis } from 'pg-postgis-types'
import postgis from 'pg-postgis-types'
Named export also available.

Connects to PostgreSQL, registers PostGIS parsers, queries a geometry, converts to GeoJSON.

// Initialize PG connection const pg = require('pg'); const postgis = require('pg-postgis-types'); const pgtypes = require('pg-custom-types'); const connectionString = 'postgres://user:pass@localhost/db'; // Fetch PostGIS OIDs and register parsers postgis(pgtypes.fetcher(pg, connectionString), null, (err) => { if (err) { console.error('Failed to register PostGIS types:', err); return; } pg.connect(connectionString, (err, client, done) => { if (err) { console.error(err); return; } client.query('SELECT ST_GeomFromText(\'POINT(1 2)\') AS geom', [], (err, result) => { done(); if (err) { console.error(err); return; } const geom = result.rows[0].geom; console.log(geom.toGeoJSON()); client.end(); }); }); });
Debug
Known issues
breakingVersion 3.0.0 changed API: requires pg-custom-types for OID fetching; removed internal 'pg-types' dependency.
fix
Update to pg-custom-types and adjust fetcher usage as per new docs.
affects: <3.0.0
deprecatedCallback-based API; no Promise or async/await support.
fix
Wrap in a Promise manually or migrate to a more modern library.
affects: >=3.0.0
gotchaMust call postgis() before any queries on each connection; type registration is per-pool, per-key.
fix
Call postgis() with a unique key for each connection pool.
affects: >=0.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open '.../node_modules/pg-postgis-types/index.js'
Missing or incomplete npm install; or local file corruption.
fix
Reinstall: rm -rf node_modules && npm install
TypeError: postgis is not a function
Incorrect import; CommonJS require used in ESM context or vice versa.
fix
Use correct import style: const postgis = require('pg-postgis-types') for CJS; import postgis from 'pg-postgis-types' for ESM.
TypeError: pgtypes.fetcher is not a function
pg-custom-types not installed or wrong version.
fix
npm install pg-custom-types@latest
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
pgrequiredpeer dependency - core database driver
pg-custom-typesrequiredrequired to fetch OIDs via fetcher function
wkxoptionaldefault WKB parser for geometry types
Agent activity
4 hits · last 30 days
node
4
Resources
pg-postgis-types — npm install pg-postgis-types · libregistry