---
title: "How to build a complete Next.js app with Vercel and CockroachDB"
description: "A step-by-step build of a social events app using Next.js pages, Vercel serverless API routes, and a CockroachDB free-tier cluster accessed via the Node.js pg driver."
url: "https://swe.quest/articles/how-to-build-a-complete-next-js-app-with-vercel-and-cockroachdb-31ba89caae01e73a"
canonical: "https://www.cockroachlabs.com/blog/tutorial-nextjs-vercel-cockroachdb/"
source: "Cockroach Labs"
published: "2022-04-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 11
tags: ["react","serverless","databases","frontend","javascript"]
---

# How to build a complete Next.js app with Vercel and CockroachDB

A post on [Cockroach Labs](https://swe.quest/sources/cockroachdb.md), published 2022-04-29, 11 min read, How-to. Original: [https://www.cockroachlabs.com/blog/tutorial-nextjs-vercel-cockroachdb/](https://www.cockroachlabs.com/blog/tutorial-nextjs-vercel-cockroachdb/)

## Summary

A step-by-step build of a social events app using Next.js pages, Vercel serverless API routes, and a CockroachDB free-tier cluster accessed via the Node.js pg driver. It covers creating the cluster, the events and people tables, storing the CA certificate and connection string as Vercel environment variables, and wiring a shared pg Pool config into API routes and getServerSideProps. The React-Bootstrap pages add events, list them, collect RSVPs, and show responders per event. The example code builds SQL by string interpolation and acquires pool clients without releasing them, so real apps should use parameterized queries and release connections.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [React](https://swe.quest/tags/react.md) (Web & mobile)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- JavaScript ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- React basics ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

Next.js, Vercel, CockroachDB, node-postgres, React Bootstrap, getServerSideProps

## Related posts

- [Next.js authentication using Clerk, Drizzle ORM, and Neon](https://swe.quest/articles/next-js-authentication-using-clerk-drizzle-orm-and-neon-0a85f87be532db48.md): Neon · 2024-04-01 · Medium · 9 min read · Identity & auth, React, PostgreSQL, TypeScript, Serverless
  Clerk can handle authentication for a Next.js 14 App Router app while Drizzle ORM and Neon's serverless HTTP driver store non-PII data keyed by the Clerk user ID.
- [Build and Deploy a Global Serverless Nuxt SSR App with Cloudflare Hyperdrive and Postgres](https://swe.quest/articles/build-and-deploy-a-global-serverless-nuxt-ssr-app-with-cloudflare-hyperdrive-32566cf4580232ef.md): Neon · 2024-04-05 · Medium · 12 min read · Serverless, PostgreSQL, CDN & edge, JavaScript, Caching
  A Nuxt SSR app on Cloudflare Pages can query Neon Postgres through Hyperdrive by routing Drizzle's pg-proxy driver to a separate Hono-based Cloudflare Worker that holds the Hyperdrive binding and runs queries with node-postgres.
- [How to Build a Secure Project Management Platform with Next.js, Clerk, and Neon](https://swe.quest/articles/how-to-build-a-secure-project-management-platform-with-next-js-clerk-and-neon-a23e4da79b231f5e.md): Neon · 2025-02-22 · Medium · 29 min read · Identity & auth, React, PostgreSQL, Application security, Frontend
  A security-first tutorial for building Kozi, a collaborative project management app, using Next.js, Clerk authentication and a Neon serverless Postgres database accessed through Prisma.
- [Build a serverless API using Cloudflare Workers, Drizzle ORM, and Neon](https://swe.quest/articles/build-a-serverless-api-using-cloudflare-workers-drizzle-orm-and-neon-f83c472c9d399a17.md): Neon · 2023-05-30 · Medium · 9 min read · Serverless, PostgreSQL, TypeScript, Schema migrations
  A step-by-step setup for a serverless TypeScript API on Cloudflare Workers that uses Hono for routing, Drizzle ORM for schema definition and migrations, and Neon serverless Postgres for storage.
- [Supabase is now compatible with Next.js 14](https://swe.quest/articles/supabase-is-now-compatible-with-next-js-14-76a3d4ceac89740e.md): Supabase · 2023-11-01 · Medium · 4 min read · React, Frontend, Identity & auth, JavaScript
  Supabase works across every Next.js 14 rendering context, including App Router Client and Server Components, Route Handlers, Server Actions and Middleware, plus the Pages Router data-fetching functions.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
