Serverless Postgres
Neon takes everything developers love about Postgres — reliability, performance, extensibility — and delivers it as a serverless product that helps you ship reliable, scalable applications faster than ever.
By integrating Neon with Vercel, you can deploy a fully managed Postgres database in seconds with features like database branching, autoscaling, scale-to-zero, read replicas, authorization, a Drizzle Studio-powered table editor, an AI-enabled SQL client, instant point-in-time recovery, time travel queries, a low-latency serverless driver, and more. Neon offers a generous Free Plan and paid plans that grow with you from prototype to enterprise.
In this guide, you will learn how to create a simple web application using Next.js Server Actions that captures user input via forms and inserts it into Postgres using the @neondatabase/serverless driver.
Start by connecting to a project. If you don't already have a project to connect to, you can create one. See Automatic Installation in the Next.js documentation for instructions. Please note that the following example uses App Router, so be sure use that option if creating a new Next.js project.
Run vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Run npm install @neondatabase/serverless to install the Neon serverless driver for connecting to your Neon database.
For more about our driver, see Neon serverless driver.
Navigate to the Neon SQL Editor in the Neon Console and create the application database by running this SQL command:
CREATE TABLE IF NOT EXISTS comments (comment TEXT);You can access the Neon Console from the Storage tab on your Vercel Dashboard. Select Open in Neon Console.
Create a form that allows users to input a comment with a Server Action action named create that inserts data into your Postgres database.
// File: app/page.tsximport { neon } from '@neondatabase/serverless';
export default function Page() { async function create(formData: FormData) { 'use server'; // Connect to the Neon database const sql = neon(`${process.env.DATABASE_URL}`); const comment = formData.get('comment'); // Insert the comment from the form into the Postgres database await sql('INSERT INTO comments (comment) VALUES ($1)', [comment]); }
return ( <form action={create}> <input type="text" placeholder="write a comment" name="comment" /> <button type="submit">Submit</button> </form> );}Execute the following command to run your application locally:
npm run devNavigate to http://localhost:3000 to see the comment form. Try inserting a comment. You can query your database directly from the Neon SQL Editor to validate that your application works:
SELECT * FROM comments;In this guide, you will learn how to connect SvelteKit with Neon over a secure server-side request using the @neondatabase/serverless driver.
Start by connecting to a SvelteKit project. If you don't already have a project to connect to, you can create one. For instructions, see Creating a project in the SvelteKit documentation.
Run vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Run npm install @neondatabase/serverless to install the Neon serverless driver for connecting to your Neon database.
For more about our driver, see Neon serverless driver.
In your server routes (+server.js files), use the following code snippet to connect to your Neon database:
import { neon } from '@neondatabase/serverless';
const connectionString: string = process.env.DATABASE_URL as string;const sql = neon(connectionString);
export async function load() { const response = await sql`SELECT version()`; const { version } = response[0]; return { version, };}In your +page.svelte files, use the following code snippet to fetch data from your server:
<script> export let data;</script>
<h1>Database Version</h1><p>{data.version}</p>Execute the following command to run your application locally:
npm run devYou can expect to see output similar to the following when you visit localhost:5173:
Database VersionPostgreSQL 17.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bitYou can find the source code for the application described in this guide on GitHub. See Get started with Svelte and Neon.
In this guide, you will learn how to make server-side queries to Postgres from .astro files using the @neondatabase/serverless driver.
Start by connecting to a project. If you don't already have a project to connect to, you can create one. See Installation and Setup in the Astro documentation for instructions.
Run vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Run npm install @neondatabase/serverless to install the Neon serverless driver for connecting to your Neon database.
For more about our driver, see Neon serverless driver.
In your .astro files, use the following code snippet to connect to your Neon database:
---import { neon } from '@neondatabase/serverless';
const sql = neon(import.meta.env.DATABASE_URL);
const response = await sql`SELECT version()`;const data = response[0].version;---
{data}Execute the following command to run your application locally:
npm run devYou can expect to see output similar to the following when you visit localhost:4321:
PostgreSQL 16.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bitYou can find the source code for the application described in this guide on GitHub. See Get started with Astro and Neon.
In this guide, you will learn how to connect SolidStart with Neon over a secure server-side request using the @neondatabase/serverless driver.
Start by connecting to a project. If you don't already have a project to connect to, you can create one. See Getting Started in the SolidStart documentation for instructions.
Run vercel env pull .env.development.local to make the latest environment variables available to your project locally.
Run npm install @neondatabase/serverless to install the Neon serverless driver for connecting to your Neon database.
For more about our driver, see Neon serverless driver.
To load data on the server in SolidStart, add the following code to your application to connect to your Neon database:
import { neon } from "@neondatabase/serverless";import { createAsync } from "@solidjs/router";
const getVersion = async () => { "use server"; const sql = neon(`${process.env.DATABASE_URL}`); const response = await sql`SELECT version()`; const { version } = response[0]; return version;}
export const route = { load: () => getVersion(),};
export default function Page() { const version = createAsync(() => getVersion()); return <>{version()}</>;}Run the following command to run your application locally:
npm run devYou can expect to see output similar to the following on localhost:3000:
PostgreSQL 16.0 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bitYou can find the source code for the application described in this guide on GitHub. See Get started with SolidStart and Neon.
In this guide, you will learn how to connect a Nuxt.js application to Neon using a server route and the @neondatabase/serverless driver.
Start by connecting to a Nuxt.js project. If you don't already have one, you can create one by running: npx nuxi@latest init <project-name>.
Run vercel env pull .env.development.local to make the latest environment variables from your Vercel project available locally.
Run npm install @neondatabase/serverless to install the Neon serverless driver for connecting to your Neon database.
For more about our driver, see Neon serverless driver.
In Nuxt, server-side logic resides in the server/api/ directory. Create a new file, server/api/version.get.ts, to define an API endpoint that connects to Neon and fetches the database version.
import { neon } from '@neondatabase/serverless';
export default defineEventHandler(async () => { const sql = neon(process.env.DATABASE_URL!); const [response] = await sql`SELECT version()`; return { version: response.version };});In your app.vue file, use the useFetch composable to call your new API endpoint and display the data returned from the database. Note that data.version should be enclosed in double curly brackets only. The brackets are escaped in the following example for display purposes. The escape characters (/) should not be used in your code.
<script setup> const { data, error } = await useFetch('/api/version'); </script>
<template> <div> <h1>Database Version</h1> <p v-if="data">/{/{data.version/}/}</p> <p v-else-if="error">Error fetching version</p> </div> </template>Execute the following command to run your application locally:
npm run devNavigate to http://localhost:3000. You can expect to see an output similar to the following:
Database VersionPostgreSQL 17.5 on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bitYou can find the source code for the application described in this guide on GitHub. See Get started with Nuxt.js and Neon.
There are two integration modes to select from:
Create New Neon Account: Installs the Neon Postgres native integration and creates a Neon account for you if you do not have one already. You get access to Neon features and plans. Billing is managed through Vercel. See the Install the Neon Native Integration for more information.
Link Existing Neon Account: Installs the Neon Postgres Previews Integration. Connects your Vercel project to your Neon database to create a database branch for each preview deployment. See the Install the Neon Previews Integration for more information.
Explore Neon with these resources:
Starter Templates
View all templates