Company
Date Published
Author
Cassidy Williams
Word count
274
Language
English
Hacker News points
None

Summary

In order to use environment variables in a Next.js project, a .env.local file must be created at the root and used to set variables that are only exposed to the Node.js environment. These variables can then be accessed in API routes or data fetching methods like getStaticProps, but not directly in client-facing components. To expose environment variables to the browser, they must be prefixed with NEXT_PUBLIC_. Environment variables can also be set through the Netlify UI or using the Netlify CLI. The use of environment variables offers many benefits and can be used in various aspects of a project, including build settings in netlify.toml.