Registry / testing / postgres-container

postgres-container

JSON →
library0.0.2jsnpmunverified

postgres-container is a lightweight Node.js module (v0.0.2) that programmatically starts a PostgreSQL Docker container, primarily designed for integration tests. It simplifies test setup by managing container lifecycle (start/stop) and connection details. Unlike heavy test frameworks or manual Docker commands, it offers a minimal API with zero external runtime dependencies beyond Docker. Note: version 0.0.2 is very early; API stability is not guaranteed.

npm install postgres-container
INSTALL
IMPORT
SIG · POSTGRES-CONTAINER
P
postgres-container
testingjavascriptv0.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.

postgresContainer
import postgresContainer from 'postgres-container'
const postgresContainer = require('postgres-container');
Package is ESM-only as of v0.0.2; CommonJS require() will not work.
PostgresContainer
import { PostgresContainer } from 'postgres-container'
import PostgresContainer from 'postgres-container'
Named export for ES modules; default export also exists.
default
import postgresContainer from 'postgres-container'
import { default as postgresContainer } from 'postgres-container'
Default import is the most convenient way to use the module.

Shows how to start a Postgres Docker container for integration tests, configuring image, port, credentials, and database name.

import postgresContainer from 'postgres-container'; const container = postgresContainer({ image: 'postgres:15', port: 5432, user: 'test', password: 'test', database: 'testdb' }); await container.start(); const connectionString = `postgres://${container.user}:${container.password}@localhost:${container.port}/${container.database}`; console.log(connectionString); // Run your tests... await container.stop();
Debug
Known issues
gotchaDocker must be installed and running on the host machine. The module does not install Docker.
fix
Ensure Docker is available and that the current user has permission to run Docker commands.
affects: >=0.0.1
breakingVersion 0.0.2 is a very early release; the API may change without major version bumps.
fix
Pin to exact version and test upgrades carefully.
affects: =0.0.2
gotchaThe container is not automatically removed after stop(); you may need to clean up manually to avoid dangling containers.
fix
Use container.stop() which should remove the container. Verify with `docker ps -a`.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'postgres-container'
Attempting to use CommonJS require() on an ESM-only package.
fix
Use import instead: 'import postgresContainer from "postgres-container"'
Error: Docker is not running
Docker daemon is not available on the host.
fix
Start Docker and ensure the current user has permission to run Docker (e.g., add to docker group).
Error: Port 5432 is already in use
Default PostgreSQL port is occupied by another process or container.
fix
Specify a different port in the configuration object: port: 5433
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
postgres-container — npm install postgres-container · libregistry