Next.js Discord

Discord Forum

.env.local

Unanswered
sedev26 posted this in #help-forum
Open in Discord
I am using next.js and have the .env.local file inside of the app folder to hide my api key from being exposed and it is not being read and saying undefined. How would go about to fix this? I tried to restart the server once added the api key and it doesn’t read the api key. I did install the dot env npm and that didn’t also work. Any solution for this?

6 Replies

Rose-breasted Grosbeak
It's supposed to be at the root of the project, where your package.json is, not inside the app directory, nor the src directory
And speaking of that, you might want to should do some runtime validation for your environment variables
How are you accessing env variables, it shouldn’t be null then