Instant Neon PostgreSQL Database Provisioning

0.14.0 · active · verified Wed Apr 22

`neon-new` (version 0.14.0) is a specialized command-line interface (CLI) and Software Development Kit (SDK) designed to facilitate the rapid, ephemeral provisioning of new, claimable Neon PostgreSQL databases. It aims to eliminate initial setup friction by allowing developers to instantiate a functional database with a single command or function call, without requiring immediate sign-up. The package currently ships with TypeScript types and targets Node.js environments. Its primary differentiating feature is the speed and ease of obtaining a fully functional PostgreSQL connection string, which is highly beneficial for rapid prototyping, local development, and CI/CD environments where temporary, on-demand databases are advantageous. While not having a strictly defined release cadence, the project is under active development, indicated by its pre-1.0.0 versioning, and has seen frequent updates. Users should be aware that databases generated this way are temporary and will expire if not formally claimed within 72 hours, making them ideal for short-lived use cases or as an initial stepping stone before migrating to a persistent, owned Neon project.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to programmatically create a new Neon PostgreSQL database using the SDK, save its credentials to a .env file, and log the connection details and claim URL. Requires Node.js >= 22.

import { instantPostgres } from "neon-new/sdk";
import fs from 'fs';
import path from 'path';

async function setupDatabase() {
  const dotEnvPath = path.resolve(process.cwd(), '.env');
  // Ensure .env file exists for the SDK to write to
  if (!fs.existsSync(dotEnvPath)) {
    fs.writeFileSync(dotEnvPath, '');
  }

  console.log("Creating a new Neon database...");
  const result = await instantPostgres({
    referrer: process.env.NEON_APP_REFERRER || "checklist-day-example", // REQUIRED for SDK usage
    dotEnvFile: ".env",
    dotEnvKey: "DATABASE_URL",
    envPrefix: "PUBLIC_",
    settings: {
      logicalReplication: false,
    },
  });

  console.log("Database created successfully!");
  console.log(`Pooled Connection String: ${result.databaseUrl}`);
  console.log(`Direct Connection String: ${result.databaseUrlDirect}`);
  console.log(`Claim URL (expires in 72h): ${result.claimUrl}`);
  console.log(`Credentials saved to ${dotEnvPath}`);

  // To connect, you would typically use a PostgreSQL client library (e.g., 'pg'):
  // import { Client } from 'pg';
  // const client = new Client({ connectionString: result.databaseUrl });
  // await client.connect();
  // const res = await client.query('SELECT NOW()');
  // console.log('Database time:', res.rows[0].now);
  // await client.end();
}

setupDatabase().catch(console.error);

view raw JSON →