Registry / testing / postgres-memory-server

postgres-memory-server

JSON →
library0.2.2jsnpmunverified

Spin up a real, disposable PostgreSQL or ParadeDB instance programmatically from Node.js (v20+) for testing — no Docker required. Version 0.2.2 uses embedded-postgres to bundle PostgreSQL binaries (~10MB) and auto-downloads pg_search and pgvector extensions from official releases. Unlike ephemeral Docker containers, this library avoids daemon dependency, supports snapshot/restore via template databases, and caches extension binaries in ~/.cache. It is inspired by mongodb-memory-server / redisjson-memory-server but tailored for Postgres extension-heavy workloads. Release cadence is active and frequent as of early 2025. Key differentiators: no system Postgres, no Docker, ParadeDB + pgvector support, zero-copy test isolation, cross-platform binaries (macOS arm64/x64, Linux arm64/x64, Windows x64 with limitations).

npm install postgres-memory-server
INSTALL
IMPORT
SIG · POSTGRES-MEMORY-SE
P
postgres-memory-server
testingjavascriptv0.2.2
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.

PostgresMemoryServer
import { PostgresMemoryServer } from 'postgres-memory-server'
const { PostgresMemoryServer } = require('postgres-memory-server')
ESM-only package (Node >=20). Use import syntax; require() will fail with ERR_REQUIRE_ESM.
PostgresMemoryServer.create()
const db = await PostgresMemoryServer.create()
const db = new PostgresMemoryServer()
create() is a static async factory. 'new PostgresMemoryServer()' does not exist and throws TypeError.
Client from 'pg'
import { Client } from 'pg'
import { PostgresMemoryServer } from 'pg'
'pg' is a separate peer dependency. You must import Client from the 'pg' package to connect.

Creates a disposable PostgreSQL instance, connects with pg client, runs a query, and stops the server.

import { PostgresMemoryServer } from 'postgres-memory-server'; import { Client } from 'pg'; async function run() { const db = await PostgresMemoryServer.create(); console.log('URI:', db.getUri()); const client = new Client({ connectionString: db.getUri() }); await client.connect(); const res = await client.query('SELECT version()'); console.log(res.rows[0].version); await client.end(); await db.stop(); } run().catch(console.error);
Debug
Known issues
breakingRequires Node.js >= 20. Older versions (18, 19) are not supported and will throw engine error.
fix
Upgrade Node.js to v20 or later.
affects: >=0.0.0
gotchaParallel instances may conflict on port if you don't pass explicit ports. Default port is dynamic but sharing a port across instances causes EADDRINUSE.
fix
Use getPort() or pass a unique port in options: PostgresMemoryServer.create({ port: 0 }) to auto-assign.
affects: >=0.0.0
gotchaExtension downloads use GitHub releases and Homebrew bottles. Network failures or rate limiting will cause timeout errors during first run.
fix
Check network connectivity. Use a caching proxy or pre-download extensions manually to ~/.cache/postgres-memory-server/.
affects: >=0.0.0
deprecatedNo deprecated APIs known in current version (0.2.2).
fix
N/A
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'postgres-memory-server'
Package not installed or import path incorrect.
fix
Run 'npm install -D postgres-memory-server' and ensure you use 'import { PostgresMemoryServer } from 'postgres-memory-server''.
TypeError: PostgresMemoryServer is not a constructor
Using 'new PostgresMemoryServer()' instead of static factory.
fix
Use 'PostgresMemoryServer.create()' (async) instead.
Error: listen EADDRINUSE: address already in use :::5432
Default or specified port is already occupied.
fix
Use 'getPort()' to find a free port or pass 'port: 0' to auto-assign.
Error: Cannot read properties of undefined (reading 'rows')
Client not connected or query failed silently.
fix
Ensure 'await client.connect()' before querying; check for connection errors.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies
embedded-postgresrequiredProvides bundled PostgreSQL binaries used to start the database process.
pgrequiredNode.js PostgreSQL client used internally for queries and connection management.
Agent activity
14 hits · last 30 days
node
12
Resources
postgres-memory-server — npm install postgres-memory-server · libregistry