Next.js · Senior · Question 23 of 75

How do you get configuration from an environment variable at runtime rather than at build time?

Explanation

NEXT_PUBLIC_* variables are inlined into the bundle during next build, so one Docker image can't be promoted across environments with different values. Server code reads process.env at runtime; if the value is needed on the client, pass it via props from a dynamically rendered server component.

Further reading

Problem with a question

Next.js · Senior · question 23

Test yourself

Take the Next.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz