Jan Henning
Jan Henning5mo ago

Changing default env file

I like to keep my env vars in .env but with every npx convex dev it automatically creates a .env.local leading to two env files in my project. Is there any way to configurate the file it creates/reads from?
9 Replies
Convex Bot
Convex Bot5mo ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
efekrskl
efekrskl5mo ago
Going through the source code of convex a bit (npm-packages/convex/src/cli/lib/envvars.ts:221) looks like the environment file name is based on which Framework you use and it's not configurable. so what you want is not possible IMO their logic could be improved though, because right now it doesn't really looks for the most .env looking file. So maybe open up an issue?
Jan Henning
Jan HenningOP5mo ago
Thanks for taking a look. I guess I'll move mine to .env.local to get around for now, I'm not to fussed about it. But yeah, could definitely be improved
erquhart
erquhart4mo ago
You can use the --env-file arg with convex dev to do this
antoine
antoine3mo ago
This arg doesn't create the file or write to it if it exists
No description
antoine
antoine3mo ago
For context I'm using https://dotenvx.com/ for my env vars. I'm open to adding a PR to support it + extending the logic for --env-file creating/writing files
dotenvx
dotenvx
a secure dotenv–from the creator of dotenv
erquhart
erquhart3mo ago
Looked at this more and yeah it doesn't generate the file, it expects it to be populated if you use the flag, and also has some other differences. There isn't a great built in solution for using a different file than .env.local currently. I believe dotenv can merge from multiple files, haven't used dotenvx though. But if it can, I'd maybe parse and merge .env.local in with your main .env vars.
antoine
antoine3mo ago
Yeah that's possible with dotenvx but I'd rather not maintain a scattered set of .env files + scripts for them in my repo, so I can help with contributing a solution for the CLI
ballingt
ballingt3mo ago
re this thread, some ideas are being shared on https://github.com/get-convex/convex-backend/pull/193, curious for any other thoughts

Did you find this page helpful?