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 Repomotherduckdb/nextjs-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

Image Gallery Starter

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

Chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
Chatbot thumbnail

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

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

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • AI Gateway

        One endpoint, all your models

      • Sandbox

        Isolated, safe code execution

      • Vercel Agent

        An agent that knows your stack

      • AI SDK

        The AI Toolkit for TypeScript

      • v0

        Build applications with AI

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Workflow

        Long-running workflows at scale

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
ContactDashboard
DeployView Demo
AI Gateway

One endpoint, all your models

Sandbox

Isolated, safe code execution

Vercel Agent

An agent that knows your stack

AI SDK

The AI Toolkit for TypeScript

v0

Build applications with AI

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Workflow

Long-running workflows at scale

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea