Socket
Book a DemoInstallSign in
Socket

@neondatabase/vite-plugin-postgres

Package Overview
Dependencies
Maintainers
9
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@neondatabase/vite-plugin-postgres

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.2.2
Version published
Weekly downloads
200
-20.63%
Maintainers
9
Weekly downloads
 
Created
Source

Vite-Plugin-Postgres by Neon

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.

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

npm add @neondatabase/vite-plugin-postgres

Usage

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

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

export default defineConfig({
	plugins: [postgresPlugin(), react()],
});

Configuration

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

postgresPlugin({
	env: ".env.local", // Path to your .env file (default: ".env")
	envKey: "DATABASE_URL", // Name of the env variable (default: "DATABASE_URL")
	seed: {
		type: "sql-script",
		path: "./schema.sql", // Path to SQL file to execute after database creation
	},
});
OptionTypeDescriptionDefault
envstringPath to the .env file.env
envKeystringName of the environment variableDATABASE_URL
seedobjectConfiguration for seeding the database-

seed Options

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

What gets written

  • The plugin writes both a direct connection string and a pooled connection string to your .env.
  • It also provides a claim URL (valid for 7 days) to take ownership of the database.
  • If seed is configured, the specified SQL script will be executed after database creation.

Type Definitions

interface PostgresPluginOptions {
	env: string; // Path to the .env file
	envKey: string; // Name of the environment variable
	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 neondb library directly.

See documentation on Neon for more.

Keywords

neon

FAQs

Package last updated on 27 Jun 2025

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