#Whats the preferred way of determining if you are running convex in dev mode or production?

3 messages · Page 1 of 1 (latest)

icy stream
#

Whats the preferred way of determining if you are running convex in dev mode or production?

wheat tinselBOT
#

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

#

The preferred way to determine if you are running Convex in development or production mode is to use environment variables. Here's how you can approach this:

  1. Set up environment variables:

    • For your development deployment, set an environment variable (e.g., CONVEX_ENV) to "development" in the Convex dashboard.
    • For your production deployment, set the same environment variable to "production" in the Convex dashboard.
  2. Access the environment variable in your Convex functions:
    You can then use process.env.CONVEX_ENV in your Convex functions to determine the current environment.

This approach is recommended by Convex, as mentioned in the Convex & Clerk documentation:

export default {
  providers: [
    {
      domain: process.env.CLERK_JWT_ISSUER_DOMAIN,
      applicationID: "convex",
    },
  ],
};

While this example is specific to Clerk authentication, the same principle applies for determining the environment in general.

It's important to note that Convex does not currently provide a built-in system variable to distinguish between development and production environments. Setting and using your own environment variables is the recommended approach.

For client-side code, you would typically use a different method to determine the environment, often relying on environment variables set by your frontend build process or hosting platform.

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