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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-postgres

v1.0.0-beta.4

Published

Vite dev-only plugin that bootstraps and runs a local PostgreSQL server for your app.

Readme

vite-postgres

Vite dev-only plugin that bootstraps and runs a local PostgreSQL server for your app.

  • Runs on vite dev only (apply: 'serve')
  • Uses your system Postgres binaries (initdb, postgres, createdb, pg_isready)
  • Picks a free port automatically and injects Postgres env vars for your app

Install

pnpm add -D vite-postgres

Usage

vite.config.ts

import { defineConfig } from 'vite'
import postgres from 'vite-postgres'

export default defineConfig({
  plugins: [
    postgres({
      // dbPath: '.postgres',      // persist in-repo (optional)
      // dbName: 'myapp',          // defaults to Vite root folder name
      // seedModule: 'src/seed.ts' // optional, runs after DB is ready
      // verbose: true,            // optional, inherit Postgres logs in Vite output
      // logFile: 'postgres.log',  // optional, relative to Vite root (ignored if verbose)
    }),
  ],
})

Then start Vite. Your app can connect using the injected env:

  • PGHOST=127.0.0.1
  • PGPORT=<free port>
  • PGDATABASE=<db name>
  • PGDATA=<data directory>

Example connection strings:

psql "host=$PGHOST port=$PGPORT dbname=$PGDATABASE"
# or (common default)
psql "postgresql://127.0.0.1:$PGPORT/$PGDATABASE"

Options

export interface VitePostgresOptions {
  dbPath?: string
  dbName?: string
  seedModule?: string
  verbose?: boolean
  logFile?: string
}
  • dbPath: Postgres data directory. Default: ${os.tmpdir()}/vite-postgres/<root>-<hash>
  • dbName: Database name. Default: Vite root folder name
  • seedModule: Module path (relative to Vite root) to execute after the DB is ready
  • verbose: Inherit Postgres stdout/stderr in the Vite process. Default: false (logs go to a file)
  • logFile: Where to write Postgres logs (relative to Vite root). Default: ${PGDATA}/postgres.log (ignored if verbose)

Seeding

If seedModule is set, it’s loaded via server.ssrLoadModule(...) after:

  1. initdb (only if PG_VERSION missing)
  2. postgres started
  3. pg_isready succeeds
  4. createdb attempted (ignored if it already exists)

The module can be TS/ESM and can run whatever you want (migrations, seed data, etc).

Notes / behavior

  • Auth is initialized with --auth=trust (no password). This is for local dev.
  • Logs go to ${PGDATA}/postgres.log to keep Vite output clean (unless verbose is enabled).
  • The Postgres process is terminated when Vite exits (SIGINT for fast shutdown).

Requirements

  • PostgreSQL installed and on your PATH (initdb, postgres, createdb, pg_isready)
  • Node compatible with Vite 7+

Troubleshooting

  • Failed to initialize DB. Ensure "initdb" is in your PATH.: install Postgres (or add its bin/ directory to PATH).
  • Port conflicts: the plugin chooses a free port each run; read process.env.PGPORT from your app instead of hard-coding 5432.