npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pg-ephemeral

v0.5.1

Published

Provides ephemeral PostgreSQL instances for testing, wrapping the pg-ephemeral project binary

Readme

pg-ephemeral npm Package

Node.js wrapper for pg-ephemeral. Installs the platform-specific binary via optional dependencies and provides a TypeScript API for ephemeral PostgreSQL instances.

Published on npm: pg-ephemeral

Installation

npm install pg-ephemeral

Platform binaries are installed automatically for linux-x64, linux-arm64, and darwin-arm64.

Usage

Direct connection

import { withConnection } from 'pg-ephemeral';

await withConnection(async (client) => {
  const result = await client.query('SELECT 1 AS value');
  console.log(result.rows[0].value);
});

withConnection yields a connected pg.Client and closes it after the callback.

Server handle

import { withServer } from 'pg-ephemeral';

await withServer(async (server) => {
  console.log(server.url);  // => "postgres://postgres:[email protected]:54321/postgres"
});

withServer yields a Server with a .url property. The container shuts down after the callback.

Options

Both withConnection and withServer accept an options object:

| Option | Description | Default | |----------------|--------------------------------------------------|------------| | instanceName | Target instance from database.toml | "main" | | config | Path to a database.toml config file | null |

await withConnection(async (client) => {
  await client.query('SELECT 1');
}, { instanceName: 'analytics', config: 'path/to/database.toml' });

Manual lifecycle

For cases where the callback form doesn't fit:

import { start } from 'pg-ephemeral';

const server = await start();
// ... use server.url ...
await server.shutdown();

Utilities

import { version, platformSupported, binaryPath } from 'pg-ephemeral';

version();            // => "0.2.0"
platformSupported();  // => true
binaryPath();         // => "/path/to/pg-ephemeral"

Test Framework Integration

Jest

Use globalSetup/globalTeardown to manage the container lifecycle and share the URL via process.env:

// jest.globalSetup.ts
import { start } from 'pg-ephemeral';

export default async function globalSetup() {
  const server = await start();
  process.env.DATABASE_URL = server.url;
  (globalThis as any).__pgEphemeralServer = server;
}

// jest.globalTeardown.ts
export default async function globalTeardown() {
  await (globalThis as any).__pgEphemeralServer?.shutdown();
}

Then connect via the environment variable in your tests:

import { Client } from 'pg';

let client: Client;

beforeAll(async () => {
  client = new Client({ connectionString: process.env.DATABASE_URL });
  await client.connect();
});

afterAll(async () => {
  await client.end();
});

it('inserts a user', async () => {
  await client.query("INSERT INTO users (name) VALUES ('alice')");
  const result = await client.query('SELECT name FROM users');
  expect(result.rows[0].name).toBe('alice');
});

Prisma

Use globalSetup to start the container and deploy migrations before tests run:

// jest.globalSetup.ts
import { start } from 'pg-ephemeral';
import { execSync } from 'node:child_process';

export default async function globalSetup() {
  const server = await start();
  process.env.DATABASE_URL = server.url;
  execSync('npx prisma migrate deploy', { env: process.env });
  (globalThis as any).__pgEphemeralServer = server;
}

// jest.globalTeardown.ts
export default async function globalTeardown() {
  await (globalThis as any).__pgEphemeralServer?.shutdown();
}

Then use PrismaClient in your tests as usual:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

afterAll(async () => {
  await prisma.$disconnect();
});

it('creates a user', async () => {
  const user = await prisma.user.create({ data: { name: 'alice' } });
  expect(user.name).toBe('alice');
});

Requirements

  • Node.js >= 20
  • Docker Engine 20.10+ / Docker Desktop 4.34+, or Podman 5.3+