How to Use Environment Variables in Next.js (Without Leaking Them to the Browser)
Learn how to use .env files in Next.js correctly. Understand NEXT_PUBLIC_, avoid common mistakes, and set variables in Vercel and Cloudflare.
5 articles
Next.js guides written against the App Router and real deployments, not toy examples. Coverage includes how environment variables actually resolve across server components, client bundles, and edge runtimes, implementing dark mode with no flash of wrong theme on first paint, wiring Husky, Prettier, and lint-staged into a Next.js repository, and replacing middleware with a proxy when the edge runtime becomes the bottleneck. There is also an extended Next.js interview question set. Where a technique depends on a specific Next.js version or rendering mode, the article says which one it was verified on.
Learn how to use .env files in Next.js correctly. Understand NEXT_PUBLIC_, avoid common mistakes, and set variables in Vercel and Cloudflare.
Set up Husky v9, Prettier, and lint-staged in your Next.js project. Step-by-step guide covering pre-commit hooks with the correct 2026 config.
Add dark mode to your Next.js App Router app without the white flash. Complete guide covering next-themes, Tailwind CSS v4 setup, and Cloudflare Pages.
30 Next.js interview questions with full answers: App Router, Server Components, use cache, PPR, Turbopack, and auth. Updated for Next.js 15 and 16.
Next.js 16 renamed middleware.ts to proxy.ts, and it's not just a name change. Here's what the runtime switch means and how to migrate a real auth-check file.