NextJsEnvironment Variables

Store sensitive data like API keys using environment variables. Use .env.local for development and process.env to access them in code.

.env.local
NEXT_PUBLIC_API_URL=https://api.example.com

export async function getStaticProps() {
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/data`);
  const data = await res.json();
  return { props: { data } };
}