Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

vite-plugin-db

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-db

This Vite plugin instantly provisions a Postgres instance (via Neon) and injects the connection string into your `.env` file, so you can start developing immediately.

latest
npmnpm
Version
0.7.0
Version published
Weekly downloads
793
-55.17%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-db

This Vite plugin instantly provisions a Postgres instance (via Neon) and injects the connection string into your .env file, so you can start developing immediately.

Note: This package was previously named @neondatabase/vite-plugin-postgres. The old package is now deprecated. If you're upgrading, simply replace it with vite-plugin-db in your imports and package.json.

How it works

  • On first vite dev, the plugin checks for a DATABASE_URL (or your configured key) in your .env.
  • If not found, it creates a claimable Neon database and writes the connection string to your .env.
  • The plugin is a noop in production builds.

Installation

Package ManagerCommand
npmnpm add -D vite-plugin-db
pnpmpnpm add -D vite-plugin-db
yarnyarn add -D vite-plugin-db
bunbun add -D vite-plugin-db
denodeno add -D npm:vite-plugin-db

Usage

⚠️ BREAKING CHANGE in v3.0.0: The referrer option is now required.

Add the plugin as the first entry in your Vite config:

import { postgres } from "vite-plugin-db";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
	plugins: [
		postgres({
			referrer: "github:username/repo-name", // REQUIRED
		}),
		react(),
	],
});

Configuration

You can pass an options object to customize the .env file path, the environment variable name, and database seeding:

postgres({
	referrer: "your-app-name", // REQUIRED - for tracking and affiliates
	env: ".env.local", // Path to your .env file (default: ".env")
	envKey: "DATABASE_URL", // Name of the env variable (default: "DATABASE_URL")
	envPrefix: "VITE_", // Prefix for public env vars (default: "VITE_")
	settings: {
		logicalReplication: false, // Enable logical replication (default: false)
	},
	seed: {
		type: "sql-script",
		path: "./schema.sql", // Path to SQL file to execute after database creation
	},
});
OptionTypeDescriptionRequiredDefault
referrerstringReferrer identifier for tracking✅ Yes-
envstringPath to the .env fileNo.env
envKeystringName of the environment variableNoDATABASE_URL
envPrefixstringPrefix for public environment variablesNoVITE_
settingsobjectDatabase configuration settingsNo-
seedobjectConfiguration for seeding the databaseNo-

settings Options

PropertyTypeDescriptionDefault
logicalReplicationbooleanEnable logical replicationfalse

seed Options

PropertyTypeDescriptionDefault
typestringType of seeding (currently only "sql-script")-
pathstringPath to SQL file to execute after creation-

What gets written

The plugin writes the following environment variables to your .env:

VariableDescription
DATABASE_URLThe pooler connection string (default connection)
DATABASE_URL_DIRECTThe direct connection string
{envPrefix}POSTGRES_CLAIM_URLClaim URL (valid for 72 hours) to take ownership of the DB

Note: The pooler connection is now the default for DATABASE_URL (as of the latest version). The pooler provides connection pooling and is recommended for most use cases, especially serverless environments.

If seed is configured, the specified SQL script will be executed after database creation.

Type Definitions

interface PostgresPluginOptions {
	referrer: string; // Required - Referrer identifier for tracking
	env?: string; // Path to the .env file
	envKey?: string; // Name of the environment variable
	envPrefix?: string; // Prefix for public environment variables
	settings?: {
		logicalReplication?: boolean; // Enable logical replication (default: false)
	};
	seed?: {
		type: "sql-script";
		path: string;
	};
}

FAQ

What if I already have a DATABASE_URL env var?

The plugin will not overwrite it. Remove the variable if you want to generate a new Neon database.

Is this safe to run on CI when building for production?

The plugin is a noop in production mode (vite build), so it won't create databases or modify your .env in CI.

Can I use this with other frameworks?

Yes, this plugin is framework-agnostic. The example uses React, but you can use it with any Vite-compatible framework.

Advanced

If you want to generate claimable databases outside of Vite, use the get-db library directly.

See documentation on Neon for more.

Keywords

neon

FAQs

Package last updated on 18 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts