Registry / database / neopg
library2.3.1jsnpmunverified

NeoPG is a high-performance, zero-dependency PostgreSQL ORM for Node.js, built on top of postgres.js. Current stable version is 2.3.1. It provides a hybrid API combining chainable query builder methods with tagged template literals, and includes automatic schema synchronization, model generation via CLI, and Snowflake-like ID generation. Major differentiators are its minimal dependency footprint (zero external dependencies beyond the vendored client), hybrid API, and built-in auto-sync for tables and indices. Release cadence is irregular; last update was on the npm registry.

npm install neopg
INSTALL
IMPORT
SIG · NEOPG
N
neopg
databasejavascriptv2.3.1
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.

NeoPG
const NeoPG = require('neopg')
import NeoPG from 'neopg'
NeoPG uses CommonJS by default. For ESM, use import syntax but ensure your project supports it; the package does not currently offer a native ESM entry.
ModelChain
const { ModelChain } = require('neopg')
import { ModelChain } from 'neopg'
ModelChain is exported as a named export in CommonJS. Using ESM import might work if your environment supports named exports from CJS.
dataTypes
const { dataTypes } = require('neopg')
const dataTypes = require('neopg').DataTypes
The object is exported as 'dataTypes' (lowercase). Capitalization mistakes are common.

Connects to PostgreSQL, defines a User model with schema, syncs table automatically, and queries users with age=18.

const NeoPG = require('neopg'); const { ModelChain, dataTypes } = require('neopg'); const config = { host: process.env.PGHOST || 'localhost', port: parseInt(process.env.PGPORT || '5432'), database: process.env.PGDATABASE || 'my_db', user: process.env.PGUSER || 'postgres', password: process.env.PGPASSWORD || '', max: 10, idle_timeout: 30, debug: false, schema: 'public' }; const db = new NeoPG(config); class User extends ModelChain { static schema = { tableName: 'users', primaryKey: 'id', column: { id: { type: dataTypes.ID }, username: { type: dataTypes.STRING(100), required: true }, email: { type: dataTypes.STRING(255), required: true }, age: { type: dataTypes.INT, default: 18 } } }; } async function main() { const users = await User.where({ age: 18 }).select(); console.log(users); await db.close(); } main().catch(console.error);
Debug
Known issues
breakingVersion 2.0.0 introduced a breaking change in ModelChain: the static property 'tableName' must be explicitly set, whereas previously it defaulted to the class name.
fix
Add 'static tableName = 'your_table';' to your model class definition.
affects: >=2.0.0
breakingNeoPG version 2.x removed support for Node.js 10 and earlier. Minimum required Node.js version is 12.
fix
Upgrade Node.js to version 12 or later.
affects: >=2.0.0
gotchaThe 'dataTypes.ID' column type generates Snowflake-like IDs, not auto-incrementing integers. If you need auto-increment, use 'dataTypes.SERIAL' or 'dataTypes.BIGSERIAL'.
fix
For auto-increment primary key, use 'dataTypes.SERIAL' instead of 'dataTypes.ID'.
affects: >=1.0.0
gotchaAutomatic schema sync can drop columns that are not defined in the model schema. If you have existing data, migration may cause data loss.
fix
Set 'autoSync: false' in config and manage schema migrations manually.
affects: >=1.0.0
deprecatedThe 'NeoPG' constructor option 'schema' default value is 'public' in v2.3.0, but earlier versions defaulted to the database user's schema. This may affect queries.
fix
Explicitly set schema in config to avoid default changes.
affects: >=2.3.0 <2.3.0
Errors
Common errors & fixes
Error: Cannot find module 'neopg'
NeoPG is not installed or not in node_modules.
fix
Run 'npm install neopg' in your project directory.
ReferenceError: dataTypes is not defined
The dataTypes object was not imported correctly.
fix
Use 'const { dataTypes } = require('neopg');' to import it.
ModelChain is not a constructor
Trying to instantiate ModelChain directly instead of extending it.
fix
Create a class that extends ModelChain, then instantiate that class.
TypeError: db.close is not a function
The database instance was not properly initialized with 'new NeoPG(config)'.
fix
Ensure you create the instance: const db = new NeoPG(config); then use await db.close().
Upgrade
Version history
2.3.1latest on npm
Audit
Dependencies
postgres.jsrequiredNeoPG is built directly on top of postgres.js as its PostgreSQL client. The core driver is vendored internally.
Agent activity
10 hits · last 30 days
node
8
Resources
packageneopg
neopg — npm install neopg · libregistry