Deviopath › Next.js

Public Environment Variables

Easy · Environment

Next.js only puts environment variables whose name starts with NEXT_PUBLIC_ into the JavaScript bundle that is sent to the browser. All other variables (like DATABASE_URL or API secrets) stay on the server, so they never leak to users.

Write publicEnv(env) that returns a new object with only the variables whose name starts with NEXT_PUBLIC_ (names are case-sensitive).

Next: Navbar With Links