Next.js · Senior · Question 23 of 75
How do you get configuration from an environment variable at runtime rather than at build time?
- ✓Correct answer: Read
process.envon the server during dynamic rendering and pass it to the client - 2Use
NEXT_PUBLIC_- values are substituted on every request - 3Put the config in
public/env.jsand update the file manually
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.