Getting started with Neon
Advanced

Getting started with Neon

In this codelab you'll learn what a database is, create a Neon serverless PostgreSQL project, design a data model, write SQL queries, connect from Node.js and Python, and learn about Neon's unique database branching feature.

Neon vs Supabase

Both Neon and Supabase give you a cloud PostgreSQL database, but they take different approaches.

  • Neon is a focused database service — it gives you a serverless PostgreSQL instance with unique features like database branching and scale-to-zero, but you bring your own auth and API layer.
  • Supabase is a full backend platform — it bundles your database with built-in authentication, auto-generated REST APIs, realtime subscriptions, and file storage, so you can build an entire app without writing server code.
  • Choose Neon if you want a pure database with advanced features like branching and plan to build your own API.
  • Choose Supabase if you want an all-in-one backend with auth and APIs out of the box.

Want an all-in-one backend instead? Try our Getting started with Supabase codelab.

What you'll use

  • Neon A serverless PostgreSQL platform with autoscaling, branching, and a generous free tier — designed for modern cloud applications. Learn more
  • PostgreSQL The world's most advanced open-source relational database, used by companies of all sizes. Learn more
  • Connection pooler Neon's built-in connection pooler efficiently manages database connections for serverless environments where many short-lived connections are common. Learn more
30–45 min

1What is a database?

A database is an organized collection of data that your application can create, read, update, and delete. Think of it as a set of spreadsheets — each table has rows (records) and columns (fields).

Almost every application you use relies on a database behind the scenes:

Real-world examples

  • User accounts — email, password hash, display name, profile photo URL
  • Blog posts — title, content, author, publish date, tags
  • E‑commerce stores — product catalog, shopping cart, order history
  • Analytics dashboards — page views, click events, session data

When you build a web application, the database is where all the important information lives. The frontend (what users see) talks to a backend (server) that reads and writes to the database.

💡 Where does a database fit?

If you've completed our Deploy web apps with Vercel codelab or the Getting started with Python codelab, you've already built pieces of a web application. A database is the missing piece that lets your app store and retrieve real data.

2Why cloud databases?

Traditionally, running a database meant setting up a server, installing database software, managing backups, and handling security patches. Cloud databases remove all of that:

  • No server to manage — the provider handles infrastructure, backups, and updates
  • Accessible from anywhere — connect from your local machine, a server, or an edge function
  • Scales automatically — handles traffic spikes without manual intervention
  • Free tiers — most providers offer generous free plans perfect for learning and side projects

Neon and Supabase are two popular cloud database platforms. Both use PostgreSQL under the hood, but each adds unique features on top.

3What is Neon?

Neon is a serverless PostgreSQL platform that separates storage and compute. This architecture enables unique features like instant branching, autoscaling, and scale-to-zero — meaning you only pay for the compute you actually use.

What Neon gives you

  • Serverless PostgreSQL A fully managed PostgreSQL database that scales automatically and suspends when idle to save costs.
  • Branching Create instant, copy-on-write branches of your database — like Git branches, but for your data.
  • Autoscaling Compute automatically scales up when traffic increases and scales down when it drops.
  • Scale-to-Zero When your database is idle, compute scales down to zero — you only pay when it's in use.
  • Connection pooling Built-in connection pooling via PgBouncer handles thousands of concurrent connections efficiently.

Because Neon focuses purely on being the best PostgreSQL database, it's a great choice when you want a powerful, standards-compliant database with modern cloud-native features.

💡 Neon vs. Supabase: If you want an all-in-one platform with auth, storage, and a REST API built in, check out our Getting started with Supabase codelab.

4Create a Neon project

Let's create your first Neon project:

  1. Go to console.neon.tech
  2. Sign up with GitHub (recommended), Google, or email.
  3. Click "New Project," choose a project name and a region close to you.
  4. Neon will create your project and show you a connection string.

Your connection string looks like this:

Terminal
postgresql://username:password@ep-cool-name-123456.us-east-2.aws.neon.tech/neondb?sslmode=require

⚠️ Keep your connection string secret! The connection string contains your database password. Never commit it to Git. Use environment variables (.env files) to store it securely.

5Design your data model

Before creating any tables, take a moment to think about your data model. A data model defines what information your app will store and how the pieces relate to each other.

This is arguably the most important step in building any application. A well-designed data model makes everything easier — queries are simpler, performance is better, and adding new features is straightforward.

⚠️ Think before you build! Changing your data model after your app is in production is much harder than getting it right from the start. Spend time here — it pays off.

Here's an example: imagine you're building an online store. You need products and orders:

Example: e‑commerce data model

Here's how you might define the tables in SQL:

Document contents
-- Create a table for products
CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  description TEXT,
  price_cents INTEGER NOT NULL,
  in_stock BOOLEAN DEFAULT true,
  created_at TIMESTAMPTZ DEFAULT now()
);

-- Create a table for orders
CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  customer_email TEXT NOT NULL,
  product_id INTEGER REFERENCES products(id),
  quantity INTEGER DEFAULT 1,
  created_at TIMESTAMPTZ DEFAULT now()
);

Tips for designing your data model:

  • Choose appropriate primary key types — SERIAL for simple auto-incrementing IDs, UUID for distributed systems
  • Always add a created_at timestamp — you'll need it for sorting and debugging
  • Use foreign keys (REFERENCES) to connect related tables
  • Add sensible default values (DEFAULT true, DEFAULT now()) to reduce the data you need to send with every insert

6Create tables & insert data

Now let's create a real table using the Neon SQL Editor. We'll start with a simple todos table:

  1. Open your project in the Neon console.
  2. Go to the SQL Editor and paste the following SQL:
Document contents
CREATE TABLE todos (
  id SERIAL PRIMARY KEY,
  task TEXT NOT NULL,
  is_complete BOOLEAN DEFAULT false,
  created_at TIMESTAMPTZ DEFAULT now()
);

Now add some test data and verify it:

Document contents
INSERT INTO todos (task) VALUES ('Learn Neon');
INSERT INTO todos (task) VALUES ('Build my first app');
INSERT INTO todos (task, is_complete) VALUES ('Create an account', true);

SELECT * FROM todos;

7Connect from your application

Now let's connect to your Neon database from an actual application. Here's how to do it in both Node.js and Python:

🟢 Node.js

Install the Neon serverless driver:

Terminal
npm install @neondatabase/serverless
Document contents
import { neon } from '@neondatabase/serverless';

const sql = neon(process.env.DATABASE_URL!);

// Fetch all todos
const todos = await sql`SELECT * FROM todos`;
console.log(todos);

// Insert a new todo
await sql`INSERT INTO todos (task) VALUES (${'Deploy to Vercel'})`;

// Update a todo
await sql`UPDATE todos SET is_complete = true WHERE id = ${1}`;

// Delete a todo
await sql`DELETE FROM todos WHERE id = ${1}`;

🐍 Python

Install the PostgreSQL adapter:

Terminal
pip install psycopg2-binary
Terminal
import psycopg2
import os

conn = psycopg2.connect(os.environ['DATABASE_URL'])
cur = conn.cursor()

cur.execute("SELECT * FROM todos")
rows = cur.fetchall()
print(rows)

cur.close()
conn.close()

Need to set up your development environment? See our Getting started with Node.js & npm or Getting started with Python codelabs.

8Database branching

Neon's standout feature is database branching. Just like Git lets you create branches of your code, Neon lets you create branches of your entire database — including all data and schema.

Branches are instant, copy-on-write snapshots. They don't duplicate storage, so they're lightweight and free to create. Here are some use cases:

  • Testing — create a branch to test a migration before running it on production
  • Development — give each developer their own database branch with real data
  • Previews — pair a Neon branch with a Vercel preview deployment for full-stack previews

You can create branches from the Neon console, the CLI, or the API. Each branch gets its own connection string.

💡 Like Git, but for databases: If you've used Git branches before (from our Getting started with GitHub codelab), Neon branching works the same way — create a branch, experiment freely, and merge or discard when you're done.

9Neon extras

Beyond the core database, Neon offers several features designed for modern cloud applications:

🔌 Connection pooling

Built-in PgBouncer connection pooling handles thousands of concurrent connections — essential for serverless environments where many short-lived functions connect at once.

📈 Autoscaling

Neon automatically adjusts compute resources based on demand. During traffic spikes, it scales up; during quiet periods, it scales down — you only pay for what you use.

⏸️ Auto-suspend

After a period of inactivity, Neon suspends compute entirely (scale-to-zero). It resumes in about 500ms when the next query arrives. Perfect for development and staging databases.

🔗 Integrations

Neon integrates natively with Vercel (one-click setup), GitHub Actions, and many ORMs (Prisma, Drizzle, TypeORM). It also supports the standard PostgreSQL wire protocol.

🆓 Free plan limits

  • 0.5 GiB storage
  • 24 hours/month active compute
  • 10 database branches
  • Unlimited projects
  • Autoscaling up to 2 CU

📖 Lesson: See how databases fit into web application architecture in our Elements of a web application lesson.

🎉

You're all set!

You now have a Neon project with a database, tables, and connections from both Node.js and Python. You also understand branching — Neon's powerful feature for safe development and testing!

Back to codelabs

How was this codelab?

Let us know what you thought — suggestions, issues, or anything else.

Getting started with Neon