Skip to main content

Data Stores for Next.jss

Data Stores in Next.js refers to connecting an app to databases and managing configuration safely. Server code talks to Postgres, MySQL or MongoDB through a driver or an ORM such as Prisma or Drizzle. Environment variables hold connection strings, and only names starting with NEXT_PUBLIC_ reach the browser.

Stage: Full-stack Features · Part of the Next.js roadmap · Last reviewed 19 November 2026

What to learn in Data Stores

Data Stores interview questions

Which Next.js environment variables are exposed to the browser?

Only variables whose names start with NEXT_PUBLIC_ are inlined into the client bundle at build time. All others stay on the server. Never put database URLs or API secrets in a NEXT_PUBLIC_ variable, since anyone can read the shipped JavaScript.

Why do Next.js dev servers sometimes open too many database connections?

Hot reloading re-runs modules, so a new database client can be created on every edit and old connections stay open. The usual fix is to store the client on globalThis in development and reuse it, so one connection pool survives reloads.

Where Data Stores fits in the Next.js roadmap

Data Stores belongs to the Full-stack Features stage (intermediate level), which takes about 16 hours. Auth and data stores.

Back to the full Next.js roadmap