Registry / testing / postgres-node-container

postgres-node-container

JSON →
library1.0.2jsnpmunverified

A Node.js library (v1.0.2) that programmatically starts and stops a PostgreSQL Docker container from integration tests. Provides connection details (host, port, credentials) and a connection string. Released as stable with TypeScript types. Differentiates from testcontainers by being a single-purpose, minimal wrapper around Dockerode with no dependencies on test frameworks. Suitable for throwaway databases in CI or local testing.

npm install postgres-node-container
INSTALL
IMPORT
SIG · POSTGRES-NODE-CONT
P
postgres-node-container
testingjavascriptv1.0.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.

PostgresNodeContainerService
import { PostgresNodeContainerService } from 'postgres-node-container'
const PostgresNodeContainerService = require('postgres-node-container').PostgresNodeContainerService
ESM only; package has no default export. TypeScript types are included.

Starts a PostgreSQL Docker container, prints the connection string, then stops the container.

import { PostgresNodeContainerService } from 'postgres-node-container'; async function test() { const service = new PostgresNodeContainerService(); const container = await service.setupPostgresContainer(); console.log('Connection string:', container.getPostgresConnectionString()); // Use container with any PostgreSQL client await container.stop(); } test().catch(console.error);
Debug
Known issues
gotchaRequires Docker to be running and accessible by the current user.
fix
Ensure Docker daemon is running and the user has permissions to interact with it.
affects: >=1.0.0
gotchaThe container is ephemeral; data is lost when container stops. For persistent databases, mount volumes manually.
fix
Use Docker volumes or mount a host directory by extending the service.
affects: >=1.0.0
gotchaPort is randomly assigned; cannot specify a fixed port.
fix
Use the provided container fields to dynamically obtain the port.
affects: >=1.0.0
Errors
Common errors & fixes
Error: getaddrinfo ENOTFOUND localhost
Docker not running or container not fully started before connection attempt.
fix
Ensure Docker is running and await the setup promise completely. The host defaults to 'localhost' but may differ in CI environments.
TypeError: Cannot read properties of undefined (reading 'postgresHost')
Calling container properties before setup completes or using the wrong variable name.
fix
Always await setupPostgresContainer() and access properties from the resolved container object.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
dockeroderequiredrequired for managing Docker containers
Agent activity
6 hits · last 30 days
node
6
Resources
postgres-node-container — npm install postgres-node-container · libregistry