#is there some way to set dev/prod env variables

16 messages · Page 1 of 1 (latest)

serene imp
#

from the cli / locally without doing it through web console

thorny mountainBOT
#

Hi @serene imp. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, you can set environment variables for both development and production deployments directly from the CLI, without using the web console.

To set an environment variable for your development deployment:

npx convex env set <NAME> <VALUE>

To set an environment variable for your production deployment, use the --prod flag:

npx convex env --prod set <NAME> <VALUE>

You can also list, get, and remove environment variables using similar CLI commands:

  • List: npx convex env list
  • Get: npx convex env get <NAME>
  • Remove: npx convex env remove <NAME>

These commands allow you to fully manage your environment variables from your local machine or within scripts, making it easy to automate environment setup for different deployments without needing to use the web dashboard. For more details, see the Convex CLI documentation and Production > Environment Variables docs.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@serene imp Kapa.ai is still learning and improving, please let me know how I did by reacting below.

serene imp
#

@thorny mountain

does that push the env var?

thorny mountainBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Yes, setting an environment variable using the CLI (e.g., npx convex env set <NAME> <VALUE> or npx convex env --prod set <NAME> <VALUE>) immediately updates ("pushes") the environment variable to the selected deployment (dev or prod) in the cloud. This means the variable is available to your Convex functions in that deployment right after you run the command—there is no need to separately push or deploy for the environment variable to take effect. This is confirmed in the documentation and support threads, which describe these CLI commands as directly modifying the deployment's environment variables, just like the web dashboard does Production > Environment Variables CLI Reference.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@serene imp Kapa.ai is still learning and improving, please let me know how I did by reacting below.

serene imp
#

is there any way to liek set from a file? lol

#

@thorny mountain

is there any way to liek set from a file? lol

thorny mountainBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

There is currently no built-in Convex CLI command to set environment variables directly from a file (like a .env file). However, you can script this yourself by parsing your env file and running the appropriate CLI commands for each variable. This approach has been discussed by community members and support staff as a workaround, but it is not a native feature of the CLI at this time.

For example, you could write a shell script that reads each line from your .env file and calls npx convex env set for each variable. This is a common workaround mentioned in support threads, but there is no official or built-in macro/flag for this in Convex as of now Discord support thread: Env variables being pushed automatically.

If you want this feature, it has been recognized as a useful feature request by the Convex team, but for now, scripting is the recommended approach.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@serene imp Kapa.ai is still learning and improving, please let me know how I did by reacting below.

serene imp
#

@thorny mountain

thanks yeah it's prob a nice to have

thorny mountainBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

You're welcome! And yes, several community members have expressed that having a built-in way to set environment variables from a file would be a nice quality-of-life improvement. For now, scripting with the CLI is the suggested workaround, and the Convex team is aware of the interest in this feature, but there’s no official support for it yet Discord support thread: Env variables being pushed automatically.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: