Skip to content
VercelLogotypeVercelLogotype
LoginSign Up

Next.js + MotherDuck Postgres endpoint quickstart

A fast, interactive analytics dashboard built on Next.js App Router, querying MotherDuck over the Postgres endpoint.

DeployView Demo
This is an auto-uploaded thumbnail from https://vercel.com/templates/submit.

Next.js + MotherDuck Postgres endpoint quickstart

An interactive NYC Taxi analytics dashboard built on Next.js App Router, querying MotherDuck over the Postgres endpoint with the standard pg driver.

The template queries MotherDuck's public sample_data.nyc.taxi share, so you get a working dashboard the moment you deploy.

Deploy

Or install the MotherDuck Native Integration from the Vercel Marketplace — it provisions a database and sets the required environment variables for you.

What's inside

  • App Router home page (src/app/page.tsx) that server-renders the usable date bounds, then hands off to a client dashboard.
  • src/app/api/dashboard/route.ts — fans out six parameterized aggregate queries in parallel (KPIs, trips-per-day, pickups-by-hour, revenue-by-payment-type, payment→rate Sankey, top pickup zones) for a given start/end range.
  • src/app/api/bounds/route.ts — returns the min/max days with meaningful trip volume so the date picker stays on well-populated data.
  • src/lib/motherduck.ts — a shared pg.Pool registered with attachDatabasePool from @vercel/functions, so connections survive and shut down cleanly across warm invocations on Fluid Compute.
  • src/components/dashboard.tsx — client dashboard with KPI cards, Recharts line/bar/Sankey charts, click-to-drill day view, and a bounded date-range picker.
  • shadcn/ui components (button, card, calendar, date-range-picker, popover, separator, skeleton), Tailwind CSS v4, Geist fonts, dark mode by default.

Prerequisites

  • Node.js 20 or later
  • A MotherDuck account — free tier works. Sign up at app.motherduck.com.

Getting started

# 1. Clone and install
git clone https://github.com/motherduckdb/nextjs-motherduck-pg-quickstart.git
cd nextjs-motherduck-pg-quickstart
npm install
# 2. Configure your MotherDuck token
cp .env.example .env.local
# then edit .env.local and paste your token from
# https://app.motherduck.com/settings/tokens
# 3. Run the dev server
npm run dev

Open http://localhost:3000 — the dashboard auto-loads the full date range from sample_data.nyc.taxi. Click any point on the trips-per-day line to drill into a single day.

How it works

The Postgres endpoint lets MotherDuck speak the Postgres wire protocol, so any Postgres client — including pg on a Vercel Function — can run full DuckDB SQL against it. This template wires up a pooled connection once and shares it across requests:

// src/lib/motherduck.ts
const pool = new Pool({
connectionString: `postgresql://user:${token}@${host}:5432/${DATABASE}`,
ssl: { rejectUnauthorized: true },
max: 10,
idleTimeoutMillis: 5000,
});
attachDatabasePool(pool); // graceful shutdown on Fluid Compute

Route handlers borrow a client from the pool, run parameterized queries in parallel with Promise.all, and return JSON. No ORMs, no code generation, no cold-start cost beyond the first Postgres handshake.

Environment variables

See .env.example for the full list with inline documentation.

VariableRequiredDescription
MOTHERDUCK_TOKENyesYour MotherDuck access token (JWT).
MOTHERDUCK_HOSTnoMotherDuck Postgres endpoint host. Defaults to pg.us-east-1-aws.motherduck.com.

The template is wired to MotherDuck's public sample_data share, so the database name is hard-coded in src/lib/motherduck.ts rather than surfaced as an env var. Change the DATABASE constant there if you repoint the template at your own database.

Learn more

  • MotherDuck × Vercel integration guide
  • Postgres endpoint docs
  • Next.js App Router
  • Vercel Fluid Compute

License

MIT

GitHub
Ownermotherduckdb
Repositorynextjs-motherduck-pg-quickstart
LicenseView License
Use Cases
Starter
Stack
Next.js
Tailwind

Related Templates

Next.js Boilerplate

Get started with Next.js and React in seconds.
Next.js Boilerplate thumbnail

eve Chat Template

A persisted Next.js chat template for eve, built with shadcn/ui, Tailwind CSS, Streamdown, Better Auth, Drizzle, and Neon.
eve Chat Template thumbnail

Image Gallery Starter

An image gallery built on Next.js and Vercel Blob.
Image Gallery Starter thumbnail

Agent Stack

  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • eveNew
  • ConnectNew

Core Platform

  • CI/CD
  • Content Delivery
  • Fluid Compute
  • Observability

Security

  • Platform Security
  • WAF
  • Bot Management
  • Bot ID

Tools

  • Vercel DropNew
  • Vercel Agent
  • Vercel PluginNew
  • Agent Skills
  • Next.js
  • Domains
  • v0

Frameworks

  • eveNew
  • Nuxt
  • SvelteKit
  • Nitro
  • Turborepo
  • Tanstack Start
  • FastAPI
  • xmcp
  • All frameworks

SDKs

  • Vercel SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDKNew
  • Queues SDKNew
  • Streamdown

Build

  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
  • Platform Engineers
  • Design Engineers

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Articles
  • Community

Explore

  • Customers
  • Marketplace
  • Templates
  • Partner Finder
  • Vercel + AWS

Company

  • About
  • Careers
  • Press
  • Events
  • Startups
  • Shipped on Vercel
  • Open Source Program
  • Enterprise
  • Pricing
  • Help

Legal & Trust

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DPA
  • Acceptable Use Policy
  • Legal (all documents)
  • Trust Center
  • Status

Social

  • GitHub
  • X
  • LinkedIn
  • YouTube
  • Instagram
  • VercelVercel
Agent Stack
  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • eve
Core Platform
  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • CI/CD
Tools
  • Next.js
  • Vercel Agent
  • Vercel Plugin
  • Domains
  • v0
Learn
  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base
Build
  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
Explore
  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Community
EnterprisePricing
Contact
Log InSign Up
Dashboard

Products

Agent Stack

  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • eve

Core Platform

  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • CI/CD

Tools

  • Next.js
  • Vercel Agent
  • Vercel Plugin
  • Domains
  • v0
Resources

Learn

  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base

Build

  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce

Explore

  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Community
Enterprise
Pricing
Sign UpLog In
Contact
DeployView Demo

Loading status…

Select a display theme: