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();
});
});
});
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.
fixReinstall: rm -rf node_modules && npm install
TypeError: postgis is not a function
Incorrect import; CommonJS require used in ESM context or vice versa.
fixUse 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.
fixnpm install pg-custom-types@latest
Audit
Dependencies
pgrequiredpeer dependency - core database driver
pg-custom-typesrequiredrequired to fetch OIDs via fetcher function
wkxoptionaldefault WKB parser for geometry types