Querying for dev/preview/prod status within code?
Does Convex offer a way to query for whether the app is dev, preview, or prod? I can use
process.env.NODE_ENV
to check for prod or dev but it registers preview deploys as production. (This is just the way NODE_ENV works so I’m wondering if there is an equivalent CONVEX_ENV of sorts)5 Replies
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!
Haven't been able to find any info about this in the docs for Environment Variables or Preview Deployments
The recommended way is to set an environment variable that is different between prod/dev/preview. each deployment can have its own environment variables
You could set the env variable to preview in https://docs.convex.dev/production/environment-variables#project-environment-variable-defaults which would get picked up by new preview deployments. It would also apply to new dev deployments, but you could have instructions for other devs in the CONTRIBUTORS.md with something like
Run npx convex env set CONVEX_ENV dev
after you create your dev deployment
Sweet, I'll do that for now. Would love if this was something Convex could support out-of-the-box, seems like a potentially common use case!