Registry / database / slim-node-postgres

slim-node-postgres

JSON →
library4.0.1jsnpmunverified

Slim Node Postgres is a lightweight PostgreSQL database abstraction layer for Node.js that simplifies connection pooling and prepared statements. Version 4.0.1 provides a promise-based API with methods like query, execute, insert, getOne, getValue, and exists. It uses named parameters with @ syntax and returns typed results. Compared to raw pg or ORMs like Sequelize/TypeORM, it offers minimal overhead and easy setup for projects that need a simple, pool-managed client without full ORM features. Release cadence is sporadic; it has TypeScript definitions built in. Requires pg and its types as peer dependencies.

npm install slim-node-postgres
INSTALL
IMPORT
SIG · SLIM-NODE-POSTGRES
S
slim-node-postgres
databasejavascriptv4.0.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.

SlimNodePostgres
import { SlimNodePostgres } from 'slim-node-postgres'
const SlimNodePostgres = require('slim-node-postgres').SlimNodePostgres
ESM default is TypeScript-friendly; CJS require needs .SlimNodePostgres
ExecuteResult
import { ExecuteResult } from 'slim-node-postgres'
const ExecuteResult = require('slim-node-postgres').ExecuteResult
Import type for query results
SlimNodePostgres (default)
import SlimNodePostgres from 'slim-node-postgres'
require('slim-node-postgres').default
Default export is available in TypeScript but not commonly used; most examples use named import

Shows how to initialize SlimNodePostgres with a connection string, perform queries with named parameters, insert using the convenient insert method, and check for existence using the exists method.

import { SlimNodePostgres, ExecuteResult } from 'slim-node-postgres'; // Create a single instance for connection pooling const db = new SlimNodePostgres(process.env.DATABASE_URL ?? 'postgres://user:pass@localhost:5432/mydb'); // Query users interface User { id: number; username: string; } async function getUsers(): Promise<User[]> { const users = await db.query<User>('SELECT * FROM "user" WHERE active = @active', { active: true }); return users; } // Insert a new user async function addUser(username: string): Promise<ExecuteResult> { const result = await db.insert('"user"', ['username'], [username]); console.log(`Inserted with id ${result.insertId}`); return result; } // Check if user exists async function userExists(id: number): Promise<boolean> { return db.exists('SELECT 1 FROM "user" WHERE id = @id LIMIT 1', { id }); }
Debug
Known issues
breakingVersion 4.0 removed automatic conversion of @params to $1 style; now uses pg's built-in parameterized queries with @ syntax. Existing code relying on old behavior may break.
fix
Update to use @param syntax as documented; no manual $N replacement needed.
affects: <4.0.0
deprecatedThe constructor accepts connection string or options object; passing a raw pool instance is deprecated and may be removed.
fix
Always pass connection string or options object to the constructor.
affects: >=3.0.0 <5.0.0
gotchaTable and column names are not escaped in the insert method; they are passed directly to the query, which can lead to SQL injection if user input is used.
fix
Sanitize or whitelist table/column names before passing to insert.
affects: *
gotchaConnection pool is managed internally but not explicitly closed; use db.close() to release pool.
fix
Call db.close() in shutdown hooks to avoid hanging connections.
affects: *
deprecatedThe execute() method returns ExecuteResult which includes insertId, but insert is preferred for inserts.
fix
Use insert() for inserts to get proper insertId behavior.
affects: >=4.0.0
Errors
Common errors & fixes
Cannot find module 'pg'
Missing peer dependency pg
fix
Run 'npm install pg'
TypeError: Cannot read properties of undefined (reading 'query')
SlimNodePostgres instance created without valid connection string or before pool is ready
fix
Ensure connection string is provided and db.connect() or first query is awaited
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: malformed auth response
PostgreSQL server requires SCRAM-SHA-256 but pg and slim-node-postgres version mismatch
fix
Update pg to >=8.0 and ensure slim-node-postgres is latest
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client driver for Node.js
Agent activity
10 hits · last 30 days
node
8
Meta
1
Amazon
1
Resources
slim-node-postgres — npm install slim-node-postgres · libregistry