#local environment variable

4 messages · Page 1 of 1 (latest)

plain mantle
#

Is there a way that I can get access to the development environment variables in Convex locally? The idea is I have some function to fetch those environment variables in convex

desert loomBOT
#

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

#

Convex does not use local environment variables in the traditional sense for development. Instead, environment variables for both development and production deployments are managed through the Convex dashboard or CLI, and are stored in the cloud.

Here's how you can work with environment variables in Convex for local development:

  1. Set environment variables: You can set environment variables for your development deployment using the Convex dashboard or CLI. For example, using the CLI:

    npx convex env set API_KEY your-api-key-value
    

    CLI documentation (https://docs.convex.dev/cli#read-and-write-environment-variables)

  2. Access in Convex functions: Once set, you can access these environment variables in your Convex functions using process.env:

    const apiKey = process.env.API_KEY;
    

    Environment Variables documentation (https://docs.convex.dev/production/environment-variables#accessing-environment-variables)

  3. Local development: When you run npx convex dev, your local development will use the environment variables set for your development deployment. These are not stored in a local .env file, but are fetched from the cloud deployment.

It's important to note that Convex doesn't use a local .env file for server-side environment variables. The environment variables are always accessed from the cloud deployment, even during local development. This ensures consistency between your local development environment and the cloud environment.