DEV Community

Discussion on: Environment Variables in Next.js

Collapse
 
alekslario profile image
Aleksandrs Larionovs

It will when you deploy with now or now --prod(If you put actual envs not just "@now-auth-secret" references). I mean it works for me, not sure what kind of problems you've encountered

Thread Thread
 
akhilaariyachandra profile image
Akhila Ariyachandra

The purpose of using the .env file is to avoid committing sensitive data like the database URI or the JWT secret to the repo. In an ideal case we should avoid doing it at all costs, but if the variable isn't sensitive we could add it directly to now.json and commit it to the repo (though I still wouldn't recommend it).

Thread Thread
 
alekslario profile image
Aleksandrs Larionovs

Thats what my first comment was about, put envs in now.json and add it to git ignore. It serves the same purpose as .env

Thread Thread
 
tdotholla profile image
Kiel

don't now.json files need to get commited though?
env files never get committed...
there's also a .nowignore file specifically to ignore now stuff.....

Came here because i'm in the same boat trying to "do it right" by using now secret and .env files locally, and the env variables UI at vercel.com.

None are working in preview/prod. only locally in dev.

Thread Thread
 
alekslario profile image
Aleksandrs Larionovs • Edited

If there is no config other than your envs in now.json, there is no need to commit it. Now.json file+Vercel is one of the ways to deploy your nextjs(or other) app, it's not integral part of you repo.