NEXT_PUBLIC_ prefix

The naming rule in Next.js where only environment variables starting with NEXT_PUBLIC_ are copied into browser code.

Putting a secret in a NEXT_PUBLIC_ variable publishes it to every visitor’s browser.

In more detail

At build time Next.js replaces NEXT_PUBLIC_ variables with their values inside the client bundle, so everyone can read them. Everything else stays on the server, which is where database passwords and API keys belong.

Example

NEXT_PUBLIC_API_URL=https://api.acme.com

Related terms

Taught in

References